Mon, 24 Jun 2019 00:28:37 +0300
added a test for valid categories
header.py | file | annotate | diff | comparison | revisions | |
tests/library-standards.ini | file | annotate | diff | comparison | revisions | |
tests/subfiles.py | file | annotate | diff | comparison | revisions |
--- a/header.py Sun Jun 23 12:17:40 2019 +0300 +++ b/header.py Mon Jun 24 00:28:37 2019 +0300 @@ -27,6 +27,12 @@ return self.filetype.rsplit('Unofficial_')[1] else: return self.filetype + @property + def effective_category(self): + if self.category: + return self.category + else: + return self.description.split(' ', 1)[0] class BadHeader: def __init__(self, index, reason):
--- a/tests/library-standards.ini Sun Jun 23 12:17:40 2019 +0300 +++ b/tests/library-standards.ini Mon Jun 24 00:28:37 2019 +0300 @@ -46,3 +46,89 @@ stud16.dat = stud3-like scaling stud21a.dat = stud3-like scaling stud22a.dat = stud3-like scaling + +[categories] +Animal = +Antenna = +Arch = +Arm = +Bar = +Baseplate = +Belville = +Boat = +Bracket = +Brick = +Car = +Clikits = +Cockpit = +Cone = +Constraction = +Constraction Accessory = Constraction +Container = +Conveyor = +Crane = +Cylinder = +Dish = +Door = +Electric = +Exhaust = +Fence = +Figure = +Figure Accessory = +Flag = +Forklift = +Freestyle = +Garage = +Glass = +Grab = +Hinge = +Homemaker = +Hose = +Ladder = +Lever = +Magnet = +Minifig = +Minifig Accessory = Minifig +Minifig Footwear = Minifig +Minifig Headwear = Minifig +Minifig Hipwear = Minifig +Minifig Neckwear = Minifig +Monorail = +Obsolete = +Panel = +Plane = +Plant = +Plate = +Platform = +Propellor = +Rack = +Roadsign = +Rock = +Scala = +Screw = +Sheet Cardboard = +Sheet Fabric = +Sheet Plastic = +Slope = +Sphere = +Staircase = +Sticker = +Support = +Tail = +Tap = +Technic = +Tile = +Tipper = +Tractor = +Trailer = +Train = +Turntable = +Tyre = +Vehicle = +Wedge = +Wheel = +Winch = +Window = +Windscreen = +Wing = +Znap =
--- a/tests/subfiles.py Sun Jun 23 12:17:40 2019 +0300 +++ b/tests/subfiles.py Mon Jun 24 00:28:37 2019 +0300 @@ -206,10 +206,34 @@ sorted_dims[-1], ) +@problem_type('bad-category', + severity = 'hold', + message = lambda category: str.format( + '"{category}" is not an official category', + category = category, + ) +) +def category_test(model): + if model.header.valid: + categories = library_standards['categories'].keys() + if model.header.effective_category not in categories: + 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] + yield report_problem( + 'bad-category', + bad_object = bad_object, + category = model.header.effective_category, + ) + manifest = { 'tests': [ determinant_test, scaling_legality_test, dependent_subfile_tests, + category_test, ], }