split more tests into new files

Mon, 24 Jun 2019 10:13:13 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 24 Jun 2019 10:13:13 +0300
changeset 89
d2b277cb948e
parent 88
6a0b43a5dec0
child 90
6ae063fd27dc

split more tests into new files

librarystandards.py file | annotate | diff | comparison | revisions
tests/category.py file | annotate | diff | comparison | revisions
tests/mirrored-studs.py file | annotate | diff | comparison | revisions
tests/subfiles.py file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/librarystandards.py	Mon Jun 24 10:13:13 2019 +0300
@@ -0,0 +1,9 @@
+from configparser import ConfigParser
+from pathlib import Path
+from os.path import dirname
+
+ini_path = Path(dirname(__file__)) / 'tests' / 'library-standards.ini'
+library_standards = ConfigParser()
+
+with ini_path.open() as file:
+    library_standards.read_file(file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/category.py	Mon Jun 24 10:13:13 2019 +0300
@@ -0,0 +1,53 @@
+from testsuite import problem_type, report_problem
+import linetypes
+from librarystandards import library_standards
+
+@problem_type('bad-category',
+    severity = 'hold',
+    message = lambda category: str.format(
+        '"{category}" is not an official category',
+        category = category,
+    )
+)
+@problem_type('bad-category-in-description',
+    severity = 'hold',
+    message = lambda category: str.format(
+        'the category "{category}" must be set using !CATEGORY '
+        'and not by description',
+        category = category,
+    )
+)
+def category_test(model):
+    if model.header.valid:
+        categories = library_standards['categories']
+        illegal_categories_in_description = [
+            category_name.lower()
+            for category_name in categories.keys()
+            if ' ' in category_name
+        ]
+        has_bad_category = False
+        if model.header.effective_category not in categories.keys():
+            try:
+                bad_object = model.find_first_header_object('category')
+            except KeyError:
+                # category was not specified using !CATEGORY, blame
+                # the description instead
+                bad_object = model.body[0]
+            has_bad_category = True
+            yield report_problem(
+                'bad-category',
+                bad_object = bad_object,
+                category = model.header.effective_category,
+            )
+        # Check if the description sets a multi-word category
+        if not has_bad_category and model.header.category is None:
+            for category_name in illegal_categories_in_description:
+                if model.header.description.lower().startswith(category_name):
+                    yield report_problem(
+                        'bad-category-in-description',
+                        bad_object = model.body[0],
+                        category = category_name.title(),
+                    )
+                    break
+
+manifest = {'tests': [category_test]}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mirrored-studs.py	Mon Jun 24 10:13:13 2019 +0300
@@ -0,0 +1,25 @@
+from testsuite import problem_type, report_problem
+import linetypes
+from librarystandards import library_standards
+
+@problem_type('mirrored-studs',
+    severity = 'warning',
+    message = lambda primitive: str.format(
+        '"{primitive}" should not be mirrored',
+        primitive = primitive,
+    )
+)
+def mirrored_studs_test(model):
+    for subfile_reference in model.subfile_references:
+        # Test whether any stud subfile is mirrored.
+        # A subfile is mirrored if its determinant is negative.
+        if subfile_reference.subfile_path.startswith('stu') \
+        and subfile_reference.subfile_path != 'stud4.dat' \
+        and subfile_reference.matrix.determinant() < 0:
+            yield report_problem(
+                'mirrored-studs',
+                bad_object = subfile_reference,
+                primitive = subfile_reference.subfile_path,
+            )
+
+manifest = {'tests': [mirrored_studs_test]}
--- a/tests/subfiles.py	Mon Jun 24 09:45:41 2019 +0300
+++ b/tests/subfiles.py	Mon Jun 24 10:13:13 2019 +0300
@@ -1,15 +1,8 @@
 from testsuite import problem_type, report_problem
 import testsuite
 from geometry import *
-from os.path import dirname
-from pathlib import Path
-from configparser import ConfigParser
 import math
-ini_path = Path(dirname(__file__)) / 'library-standards.ini'
-library_standards = ConfigParser()
-
-with ini_path.open() as file:
-    library_standards.read_file(file)
+from librarystandards import library_standards
 
 @problem_type('zero-determinant',
     severity = 'hold',
@@ -230,80 +223,10 @@
                 sorted_dims[-1],
             )
 
-@problem_type('bad-category',
-    severity = 'hold',
-    message = lambda category: str.format(
-        '"{category}" is not an official category',
-        category = category,
-    )
-)
-@problem_type('bad-category-in-description',
-    severity = 'hold',
-    message = lambda category: str.format(
-        'the category "{category}" must be set using !CATEGORY '
-        'and not by description',
-        category = category,
-    )
-)
-def category_test(model):
-    if model.header.valid:
-        categories = library_standards['categories']
-        illegal_categories_in_description = [
-            category_name.lower()
-            for category_name in categories.keys()
-            if ' ' in category_name
-        ]
-        has_bad_category = False
-        if model.header.effective_category not in categories.keys():
-            try:
-                bad_object = model.find_first_header_object('category')
-            except KeyError:
-                # category was not specified using !CATEGORY, blame
-                # the description instead
-                bad_object = model.body[0]
-            has_bad_category = True
-            yield report_problem(
-                'bad-category',
-                bad_object = bad_object,
-                category = model.header.effective_category,
-            )
-        # Check if the description sets a multi-word category
-        if not has_bad_category and model.header.category is None:
-            for category_name in illegal_categories_in_description:
-                if model.header.description.lower().startswith(category_name):
-                    yield report_problem(
-                        'bad-category-in-description',
-                        bad_object = model.body[0],
-                        category = category_name.title(),
-                    )
-                    break
-
-@problem_type('mirrored-studs',
-    severity = 'warning',
-    message = lambda primitive: str.format(
-        '"{primitive}" should not be mirrored',
-        primitive = primitive,
-    )
-)
-def mirrored_studs_test(model):
-    for subfile_reference in model.subfile_references:
-        # Test whether any stud subfile is mirrored.
-        # A subfile is mirrored if its determinant is negative.
-        if subfile_reference.subfile_path.startswith('stu') \
-        and subfile_reference.subfile_path != 'stud4.dat' \
-        and subfile_reference.matrix.determinant() < 0:
-            yield report_problem(
-                'mirrored-studs',
-                bad_object = subfile_reference,
-                primitive = subfile_reference.subfile_path,
-            )
-
 manifest = {
     'tests': [
         determinant_test,
         scaling_legality_test,
         dependent_subfile_tests,
-        category_test,
-        mirrored_studs_test,
     ],
 }

mercurial