# HG changeset patch # User Teemu Piippo # Date 1561325317 -10800 # Node ID eb93feb6d3a39c09f2c2ab04dd05cc1f8f2c065a # Parent 1970afe52da4460f79d030735b5b8d74c3f7b977 added a test for valid categories diff -r 1970afe52da4 -r eb93feb6d3a3 header.py --- 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): diff -r 1970afe52da4 -r eb93feb6d3a3 tests/library-standards.ini --- 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 = diff -r 1970afe52da4 -r eb93feb6d3a3 tests/subfiles.py --- 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, ], }