summaryrefslogtreecommitdiff
path: root/gerber/tests/test_utils.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2016-11-05 21:11:09 -0400
committerGitHub <noreply@github.com>2016-11-05 21:11:09 -0400
commitd2fe4441662435e55f2dc481bf94a2729b9d6a48 (patch)
treedd60a0b21e1d1ca7258b9f978ce973354d96062c /gerber/tests/test_utils.py
parent318a81382e074a5897489299a58e029815d23492 (diff)
parent5af19af190c1fb0f0c5be029d46d63e657dde4d9 (diff)
downloadgerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.tar.gz
gerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.tar.bz2
gerbonara-d2fe4441662435e55f2dc481bf94a2729b9d6a48.zip
Merge pull request #3 from garretfick/merge-curtacircuitos
Merge curtacircuitos
Diffstat (limited to 'gerber/tests/test_utils.py')
-rw-r--r--gerber/tests/test_utils.py78
1 files changed, 62 insertions, 16 deletions
diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py
index 001a32f..35f6f47 100644
--- a/gerber/tests/test_utils.py
+++ b/gerber/tests/test_utils.py
@@ -3,8 +3,8 @@
# Author: Hamilton Kibbe <ham@hamiltonkib.be>
-from .tests import assert_equal
-from ..utils import decimal_string, parse_gerber_value, write_gerber_value
+from .tests import assert_equal, assert_raises
+from ..utils import *
def test_zero_suppression():
@@ -19,10 +19,11 @@ def test_zero_suppression():
('1000', 0.01), ('10000', 0.1), ('100000', 1.0),
('1000000', 10.0), ('-1', -0.00001), ('-10', -0.0001),
('-100', -0.001), ('-1000', -0.01), ('-10000', -0.1),
- ('-100000', -1.0), ('-1000000', -10.0), ]
+ ('-100000', -1.0), ('-1000000', -10.0),
+ ('0', 0.0)]
for string, value in test_cases:
- assert(value == parse_gerber_value(string, fmt, zero_suppression))
- assert(string == write_gerber_value(value, fmt, zero_suppression))
+ assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
+ assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
# Test trailing zero suppression
zero_suppression = 'trailing'
@@ -30,10 +31,14 @@ def test_zero_suppression():
('00001', 0.001), ('000001', 0.0001),
('0000001', 0.00001), ('-1', -10.0), ('-01', -1.0),
('-001', -0.1), ('-0001', -0.01), ('-00001', -0.001),
- ('-000001', -0.0001), ('-0000001', -0.00001)]
+ ('-000001', -0.0001), ('-0000001', -0.00001),
+ ('0', 0.0)]
for string, value in test_cases:
- assert(value == parse_gerber_value(string, fmt, zero_suppression))
- assert(string == write_gerber_value(value, fmt, zero_suppression))
+ assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
+ assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
+
+ assert_equal(write_gerber_value(0.000000001, fmt, 'leading'), '0')
+ assert_equal(write_gerber_value(0.000000001, fmt, 'trailing'), '0')
def test_format():
@@ -46,10 +51,11 @@ def test_format():
((2, 1), '1', 0.1), ((2, 7), '-1', -0.0000001),
((2, 6), '-1', -0.000001), ((2, 5), '-1', -0.00001),
((2, 4), '-1', -0.0001), ((2, 3), '-1', -0.001),
- ((2, 2), '-1', -0.01), ((2, 1), '-1', -0.1), ]
+ ((2, 2), '-1', -0.01), ((2, 1), '-1', -0.1),
+ ((2, 6), '0', 0)]
for fmt, string, value in test_cases:
- assert(value == parse_gerber_value(string, fmt, zero_suppression))
- assert(string == write_gerber_value(value, fmt, zero_suppression))
+ assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
+ assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
zero_suppression = 'trailing'
test_cases = [((6, 5), '1', 100000.0), ((5, 5), '1', 10000.0),
@@ -57,10 +63,11 @@ def test_format():
((2, 5), '1', 10.0), ((1, 5), '1', 1.0),
((6, 5), '-1', -100000.0), ((5, 5), '-1', -10000.0),
((4, 5), '-1', -1000.0), ((3, 5), '-1', -100.0),
- ((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0), ]
+ ((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0),
+ ((2, 5), '0', 0)]
for fmt, string, value in test_cases:
- assert(value == parse_gerber_value(string, fmt, zero_suppression))
- assert(string == write_gerber_value(value, fmt, zero_suppression))
+ assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
+ assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
def test_decimal_truncation():
@@ -69,8 +76,8 @@ def test_decimal_truncation():
value = 1.123456789
for x in range(10):
result = decimal_string(value, precision=x)
- calculated = '1.' + ''.join(str(y) for y in range(1,x+1))
- assert(result == calculated)
+ calculated = '1.' + ''.join(str(y) for y in range(1, x + 1))
+ assert_equal(result, calculated)
def test_decimal_padding():
@@ -81,3 +88,42 @@ def test_decimal_padding():
assert_equal(decimal_string(value, precision=4, padding=True), '1.1230')
assert_equal(decimal_string(value, precision=5, padding=True), '1.12300')
assert_equal(decimal_string(value, precision=6, padding=True), '1.123000')
+ assert_equal(decimal_string(0, precision=6, padding=True), '0.000000')
+
+
+def test_parse_format_validation():
+ """ Test parse_gerber_value() format validation
+ """
+ assert_raises(ValueError, parse_gerber_value, '00001111', (7, 5))
+ assert_raises(ValueError, parse_gerber_value, '00001111', (5, 8))
+ assert_raises(ValueError, parse_gerber_value, '00001111', (13, 1))
+
+
+def test_write_format_validation():
+ """ Test write_gerber_value() format validation
+ """
+ assert_raises(ValueError, write_gerber_value, 69.0, (7, 5))
+ assert_raises(ValueError, write_gerber_value, 69.0, (5, 8))
+ assert_raises(ValueError, write_gerber_value, 69.0, (13, 1))
+
+
+def test_detect_format_with_short_file():
+ """ Verify file format detection works with short files
+ """
+ assert_equal('unknown', detect_file_format('gerber/tests/__init__.py'))
+
+
+def test_validate_coordinates():
+ assert_raises(TypeError, validate_coordinates, 3)
+ assert_raises(TypeError, validate_coordinates, 3.1)
+ assert_raises(TypeError, validate_coordinates, '14')
+ assert_raises(TypeError, validate_coordinates, (0,))
+ assert_raises(TypeError, validate_coordinates, (0, 1, 2))
+ assert_raises(TypeError, validate_coordinates, (0, 'string'))
+
+
+def test_convex_hull():
+ points = [(0, 0), (1, 0), (1, 1), (0.5, 0.5), (0, 1), (0, 0)]
+ expected = [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]
+ assert_equal(set(convex_hull(points)), set(expected))
+ \ No newline at end of file