def processdoor(door: dict) -> dict: """ Takes a row from the item list and processes it into a dict containing door information """ price = door['Price'] cost = door['Cost'] name = door['Description'] width, height = None, None doorsize = DOORRE.search(name) if doorsize: width, height = Imperial(doorsize['width']), Imperial( doorsize['height']) weatherseal = "Full Weather Seal" in name return dict(price=price, cost=cost, name=name, width=width, height=height, weatherseal=weatherseal)
def test_stopheight(testdata=None, fail=True): """ Compares the supplied stoheight to testdata validation """ return general_test( "Stop Height", actualfunction=lambda trial: trial['door'].stopheight, targetfunction=lambda trial: Imperial(trial['stopheight']).tofloat(), errormargin_numeric=0, errormargin_ratio=.00, testdata=testdata, fail=fail)
def floatify(value): """ Very simple function to catch empty strings """ if value: try: return float(value) except: try: return float(Imperial(value)) except: pass return 0
def test_slatlength(testdata=None, fail=True): """ Compares generated curtain slat length to testdata validation """ passed = 0 out = [] for trial in testdata: actual, target = float(trial['door'].curtain.slatlength( trial['door'].curtain.slatsections()[0])), float( Imperial(trial['slatlength'])) try: assertmargin(trial['jobnumber'], target, actual) except AssertionError as e: difference = actual - target if (difference == .125 and trial['Wall Angle Thickness'] == "1/4") or\ (difference == .25 and trial['Wall Angle Thickness'] == "5/16"): ## We don't use different Wall Angle Thicknesses anymore, and these ## adjustments are corner cases, so we'll skip them print('test_slatlength: Bad Wall Angle Thickness') continue width = Imperial(trial['door'].clearopening_width).tofloat() actualdivergence = actual - width targetdivergence = target - width differencedivergence = actualdivergence - targetdivergence out.append((f"{trial['jobnumber']:<10}", f"{width:^9.04f}", f"{target:^9.04f}", f"{actual:^9.04f}", f"{targetdivergence:^9.04f}", f"{actualdivergence:^9.04f}", f"{difference:9.04f}")) if out: if fail: raisetesterror(out, testdata, headers=[ "Job Number", "Width", "Target", "Actual", "Target Div", "Actual Div", "Difference" ], title="Curtain Slat Length") return out
def parsesheet_toDoor(costingsheet: "CostingSheet") -> "NewDadsDoor.Door": """ Converts a CostingSheet Instance into a NewDadsDoor.Door """ ## Convert feet to inches (or otherwise could convert to a string) door = nddmethods.basic_torsion_door(costingsheet.width * 12, costingsheet.height * 12) table = get_table_by_name(costingsheet.workbook, "CostsTable") ## First item is header list _, *rows = table.todicts() springs = filter(lambda row: constants.SPRINGRE.match(row['Item']), rows) springs = [(constants.SPRINGRE.search(row['Item']), row['Unit/Qty'] * 12) for row in springs] wires = [ classes.Spring(wire=fixwire(spring['wire']), od=float(spring['size']), coiledlength=float(length)) for spring, length in springs ] castings = _convert_castings( filter(lambda row: constants.CASTINGRE.match(row['Item']), rows)) sockets = nddmethods.build_sockets(wires, castings) door.pipe.assembly = sockets shaft = list( filter( lambda row: row['Subcomponent'] == "Assembly" and "Solid Shaft" in row['Item'], rows)) if shaft: shaft = shaft[0] shaftsize = constants.SHAFTRE.match(shaft['Item']).group("shaftsize") shaftsize = Imperial(shaftsize) slats = list( filter( lambda row: row['Subcomponent'] == "Curtain" and "Slats" in row[ 'Item'], rows)) if slats: slats = slats[0] curtainslats = door.curtain.slatsections()[0] if "528" in slats['Item ID']: curtainslats.slat = "2 1/2 INCH FLAT SLAT" else: curtainslats.slat = "2 7/8 INCH CROWN SLAT" curtainslats.slats = slats['Qty'] return door
def test_slatlength_bad(testdata=None, fail=True): """ Ensures that test_slatlength is not succeeding on bad data """ badtestdata = [{ 'jobnumber': test['jobnumber'], 'door': test['door'], 'slatlength': Imperial(50000000000.0), 'Wall Angle Thickness': test['Wall Angle Thickness'] } for test in testdata] try: test_slatlength(testdata=badtestdata) ## We expect it to fail on Assertion except AssertionError: return else: ## This is a bad sign if fail: raise AssertionError("test_slatlength OK'd bad data") return True
def general_bad_test(testfunction, attribute, testdata=None, measure=False, fail=True): """ A wrapper to manufacture generic, simple bad tests """ if measure is True: attr = Imperial(BADDATACONSTANT) else: attr = BADDATACONSTANT badtestdata = [{ 'jobnumber': test['jobnumber'], 'door': test['door'], attribute: attr } for test in testdata] try: testfunction(testdata=badtestdata) ## We expect it to fail on Assertion except AssertionError: return else: ## This is a bad sign if fail: raise AssertionError(f"{testfunction.__name__} OK'd bad data") return True