summaryrefslogtreecommitdiff
path: root/gerber/tests/test_am_statements.py
blob: 2ba77337205c16c3b7b3895c0716d17a1a54d0b3 (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
77
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Author: Hamilton Kibbe <ham@hamiltonkib.be>

from .tests import *
from ..am_statements import *

def test_AMPrimitive_ctor():
    for exposure in ('on', 'off', 'ON', 'OFF'):
        for code in (0, 1, 2, 4, 5, 6, 7, 20, 21, 22):
            p = AMPrimitive(code, exposure)
            assert_equal(p.code, code)
            assert_equal(p.exposure, exposure.lower())


def test_AMPrimitive_validation():
    assert_raises(TypeError, AMPrimitive, '1', 'off')
    assert_raises(ValueError, AMPrimitive, 0, 'exposed')
    assert_raises(ValueError, AMPrimitive, 3, 'off')


def test_AMCommentPrimitive_ctor():
    c = AMCommentPrimitive(0, ' This is a comment *')
    assert_equal(c.code, 0)
    assert_equal(c.comment, 'This is a comment')


def test_AMCommentPrimitive_validation():
    assert_raises(ValueError, AMCommentPrimitive, 1, 'This is a comment')


def test_AMCommentPrimitive_factory():
    c = AMCommentPrimitive.from_gerber('0 Rectangle with rounded corners. *')
    assert_equal(c.code, 0)
    assert_equal(c.comment, 'Rectangle with rounded corners.')


def test_AMCommentPrimitive_dump():
    c = AMCommentPrimitive(0, 'Rectangle with rounded corners.')
    assert_equal(c.to_gerber(), '0 Rectangle with rounded corners. *')


def test_AMCirclePrimitive_ctor():
    test_cases = ((1, 'on', 0, (0, 0)),
                  (1, 'off', 1, (0, 1)),
                  (1, 'on', 2.5, (0, 2)),
                  (1, 'off', 5.0, (3, 3)))
    for code, exposure, diameter, position in test_cases:
        c = AMCirclePrimitive(code, exposure, diameter, position)
        assert_equal(c.code, code)
        assert_equal(c.exposure, exposure)
        assert_equal(c.diameter, diameter)
        assert_equal(c.position, position)


def test_AMCirclePrimitive_validation():
    assert_raises(ValueError, AMCirclePrimitive, 2, 'on', 0, (0, 0))


def test_AMCirclePrimitive_factory():
    c = AMCirclePrimitive.from_gerber('1,0,5,0,0*')
    assert_equal(c.code, 1)
    assert_equal(c.exposure, 'off')
    assert_equal(c.diameter, 5)
    assert_equal(c.position, (0,0))


def test_AMCirclePrimitive_dump():
    c = AMCirclePrimitive(1, 'off', 5, (0, 0))
    assert_equal(c.to_gerber(), '1,0,5,0,0*')
    c = AMCirclePrimitive(1, 'on', 5, (0, 0))
    assert_equal(c.to_gerber(), '1,1,5,0,0*')