summaryrefslogtreecommitdiff
path: root/gerbonara/tests/test_utils.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-30 20:11:38 +0100
committerjaseg <git@jaseg.de>2022-01-30 20:11:38 +0100
commitc3ca4f95bd59f69d45e582a4149327f57a360760 (patch)
tree5f43c61a261698e2f671b5238a7aa9a71a0f6d23 /gerbonara/tests/test_utils.py
parent259a56186820923c78a5688f59bd8249cf958b5f (diff)
downloadgerbonara-c3ca4f95bd59f69d45e582a4149327f57a360760.tar.gz
gerbonara-c3ca4f95bd59f69d45e582a4149327f57a360760.tar.bz2
gerbonara-c3ca4f95bd59f69d45e582a4149327f57a360760.zip
Rename gerbonara/gerber package to just gerbonara
Diffstat (limited to 'gerbonara/tests/test_utils.py')
-rw-r--r--gerbonara/tests/test_utils.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/gerbonara/tests/test_utils.py b/gerbonara/tests/test_utils.py
new file mode 100644
index 0000000..6f243c8
--- /dev/null
+++ b/gerbonara/tests/test_utils.py
@@ -0,0 +1,120 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Author: Hamilton Kibbe <ham@hamiltonkib.be>
+# Author: Jan Götte <code@jaseg.de>
+#
+
+import pytest
+from ..cam import FileSettings
+
+
+def test_zero_suppression():
+ # Default format
+ settings = FileSettings(number_format=(2,5), zeros='leading')
+ test_cases = [
+ ("1", 0.00001),
+ ("10", 0.0001),
+ ("100", 0.001),
+ ("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),
+ ("0", 0.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)
+
+ settings = FileSettings(number_format=(2,5), zeros='trailing')
+ test_cases = [
+ ("1", 10.0),
+ ("01", 1.0),
+ ("001", 0.1),
+ ("0001", 0.01),
+ ("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),
+ ("0", 0.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_cases = [
+ ((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, 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, 6), "0", 0),
+ ]
+ for fmt, string, value in test_cases:
+ settings = FileSettings(number_format=fmt, zeros='leading')
+ assert value == settings.parse_gerber_value(string)
+ assert string == settings.write_gerber_value(value)
+
+ test_cases = [
+ ((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),
+ ((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), "0", 0),
+ ]
+ for fmt, string, value in test_cases:
+ 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():
+ 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():
+ for fmt in (7,5), (5,8), (13,1):
+ with pytest.raises(ValueError):
+ settings = FileSettings(number_format=fmt)
+ settings.write_gerber_value(69.0)
+