summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/tests/test_utils.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-29 21:19:11 +0100
committerjaseg <git@jaseg.de>2022-01-29 21:19:26 +0100
commit6edc1bf6069f489fcc4ae11bc0523d8bfc31cfd8 (patch)
tree52c4c019ed5e37199f5efbafc17c4a096d5bbb32 /gerbonara/gerber/tests/test_utils.py
parent1d0336056f2b29a95148768bfc5e805afad27cba (diff)
downloadgerbonara-6edc1bf6069f489fcc4ae11bc0523d8bfc31cfd8.tar.gz
gerbonara-6edc1bf6069f489fcc4ae11bc0523d8bfc31cfd8.tar.bz2
gerbonara-6edc1bf6069f489fcc4ae11bc0523d8bfc31cfd8.zip
Fix zero suppression handling and remove more old files
Diffstat (limited to 'gerbonara/gerber/tests/test_utils.py')
-rw-r--r--gerbonara/gerber/tests/test_utils.py107
1 files changed, 30 insertions, 77 deletions
diff --git a/gerbonara/gerber/tests/test_utils.py b/gerbonara/gerber/tests/test_utils.py
index 68484d1..6f243c8 100644
--- a/gerbonara/gerber/tests/test_utils.py
+++ b/gerbonara/gerber/tests/test_utils.py
@@ -1,20 +1,17 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
-
+#
# Author: Hamilton Kibbe <ham@hamiltonkib.be>
+# Author: Jan Götte <code@jaseg.de>
+#
import pytest
-from ..utils import *
+from ..cam import FileSettings
def test_zero_suppression():
- """ Test gerber value parser and writer handle zero suppression correctly.
- """
# Default format
- fmt = (2, 5)
-
- # Test leading zero suppression
- zero_suppression = "leading"
+ settings = FileSettings(number_format=(2,5), zeros='leading')
test_cases = [
("1", 0.00001),
("10", 0.0001),
@@ -32,12 +29,14 @@ def test_zero_suppression():
("-1000000", -10.0),
("0", 0.0),
]
+
+ assert settings.write_gerber_value(0.000000001) == "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 value == settings.parse_gerber_value(string)
+ assert string == settings.write_gerber_value(value)
- # Test trailing zero suppression
- zero_suppression = "trailing"
+ settings = FileSettings(number_format=(2,5), zeros='trailing')
test_cases = [
("1", 10.0),
("01", 1.0),
@@ -55,18 +54,15 @@ def test_zero_suppression():
("-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 write_gerber_value(0.000000001, fmt, "leading") == "0"
- assert write_gerber_value(0.000000001, fmt, "trailing") == "0"
+ assert settings.write_gerber_value(0.000000001) == "0"
+
+ for string, value in test_cases:
+ assert value == settings.parse_gerber_value(string)
+ assert string == settings.write_gerber_value(value)
def test_format():
- """ Test gerber value parser and writer handle format correctly
- """
- zero_suppression = "leading"
test_cases = [
((2, 7), "1", 0.0000001),
((2, 6), "1", 0.000001),
@@ -85,10 +81,10 @@ def test_format():
((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)
+ settings = FileSettings(number_format=fmt, zeros='leading')
+ assert value == settings.parse_gerber_value(string)
+ assert string == settings.write_gerber_value(value)
- zero_suppression = "trailing"
test_cases = [
((6, 5), "1", 100000.0),
((5, 5), "1", 10000.0),
@@ -105,63 +101,20 @@ def test_format():
((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)
-
-
-def test_decimal_truncation():
- """ Test decimal_string truncates value to the correct precision
- """
- 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
-
-
-def test_decimal_padding():
- """ Test decimal_string padding
- """
- value = 1.123
- assert decimal_string(value, precision=3, padding=True) == "1.123"
- assert decimal_string(value, precision=4, padding=True) == "1.1230"
- assert decimal_string(value, precision=5, padding=True) == "1.12300"
- assert decimal_string(value, precision=6, padding=True) == "1.123000"
- assert decimal_string(0, precision=6, padding=True) == "0.000000"
-
+ settings = FileSettings(number_format=fmt, zeros='trailing')
+ assert value == settings.parse_gerber_value(string)
+ assert string == settings.write_gerber_value(value)
def test_parse_format_validation():
- """ Test parse_gerber_value() format validation
- """
- pytest.raises(ValueError, parse_gerber_value, "00001111", (7, 5))
- pytest.raises(ValueError, parse_gerber_value, "00001111", (5, 8))
- pytest.raises(ValueError, parse_gerber_value, "00001111", (13, 1))
+ for fmt in (7,5), (5,8), (13,1):
+ with pytest.raises(ValueError):
+ settings = FileSettings(number_format=fmt)
+ settings.parse_gerber_value('00001111')
def test_write_format_validation():
- """ Test write_gerber_value() format validation
- """
- pytest.raises(ValueError, write_gerber_value, 69.0, (7, 5))
- pytest.raises(ValueError, write_gerber_value, 69.0, (5, 8))
- pytest.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 "unknown" == detect_file_format("gerber/tests/__init__.py")
-
-
-def test_validate_coordinates():
- pytest.raises(TypeError, validate_coordinates, 3)
- pytest.raises(TypeError, validate_coordinates, 3.1)
- pytest.raises(TypeError, validate_coordinates, "14")
- pytest.raises(TypeError, validate_coordinates, (0,))
- pytest.raises(TypeError, validate_coordinates, (0, 1, 2))
- pytest.raises(TypeError, validate_coordinates, (0, "string"))
-
+ for fmt in (7,5), (5,8), (13,1):
+ with pytest.raises(ValueError):
+ settings = FileSettings(number_format=fmt)
+ settings.write_gerber_value(69.0)
-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 set(convex_hull(points)) == set(expected)