summaryrefslogtreecommitdiff
path: root/tests/test_rs274x.py
blob: dbb5f62e23d381c5e9c9cf788f33a8ebfe6b1332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>

import os
import unittest
import gerberex

class TestRs274x(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        os.chdir(os.path.dirname(__file__))
        cls.INDIR = 'data'
        cls.OUTDIR = 'outputs'
        cls.EXPECTSDIR = 'expects'
        cls.OUTPREFIX = 'RS2724x_'
        cls.METRIC_FILE = os.path.join(cls.INDIR, 'ref_gerber_metric.gtl')
        cls.INCH_FILE = os.path.join(cls.INDIR, 'ref_gerber_inch.gtl')
        cls.SQ_FILE = os.path.join(cls.INDIR, 'ref_gerber_single_quadrant.gtl')
        try:
            os.mkdir(cls.OUTDIR)
        except FileExistsError:
            pass

    def _checkResult(self, file):
        with open(file, 'r') as f:
            data = f.read()
        with open(os.path.join(self.EXPECTSDIR, os.path.basename(file)), 'r') as f:
            expect = f.read()
        self.assertEqual(data, expect)

    def test_save(self):
        outfile=os.path.join(self.OUTDIR, self.OUTPREFIX + 'save.gtl')
        gerber = gerberex.read(self.METRIC_FILE)
        gerber.write(outfile)
        self._checkResult(outfile)

    def test_to_inch(self):
        outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_inch.gtl')
        gerber = gerberex.read(self.METRIC_FILE)
        gerber.to_inch()
        gerber.format = (2,5)
        gerber.write(outfile)
        self._checkResult(outfile)

    def test_to_metric(self):
        outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_metric.gtl')
        gerber = gerberex.read(self.INCH_FILE)
        gerber.to_metric()
        gerber.format = (3, 4)
        gerber.write(outfile)
        self._checkResult(outfile)

    def test_offset(self):
        outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'offset.gtl')
        gerber = gerberex.read(self.METRIC_FILE)
        gerber.offset(11, 5)
        gerber.write(outfile)
        self._checkResult(outfile)

    def test_rotate(self):
        outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rotate.gtl')
        gerber = gerberex.read(self.METRIC_FILE)
        gerber.rotate(20, (10,10))
        gerber.write(outfile)
        self._checkResult(outfile)

    def test_single_quadrant(self):
        outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'single_quadrant.gtl')
        gerber = gerberex.read(self.SQ_FILE)
        gerber.write(outfile)
        self._checkResult(outfile)

if __name__ == '__main__':
    unittest.main()