def test_predict(self): classifier = WidgetClassifier() classifier.load_model() widget = generate_widget(is_anomaly=True) prediction = classifier.predict(widget) assert (prediction.is_good is False) widget = generate_widget(is_anomaly=False) prediction = classifier.predict(widget) assert (prediction.is_good is True)
def test_web_sink(self): """ Test to ensure we can get a widget """ widget = generate_widget() post_bad_widget_to_web(widget) assert (True)
def test_widget(self): """ Tests to ensure the assembly object can be converted to json properly """ w = generate_widget() s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) assert w2.to_json() == s
def test_table_interaction(self): w = generate_widget() tbl_cnxn = storcon.get_tbl_cnxn() w.persist_table(tbl_cnxn) w2 = Widget.from_table(tbl_cnxn, w.factory_id, w.line_id, w.serial_number) tbl_cnxn.delete_entity( "classifiedwidgets", Widget.generate_partition_key(w.factory_id, w.line_id), w.serial_number) assert (w.serial_number == w2.serial_number) assert (len(w2.telemetry) > 3)
def test_widget_no_classification(self): """ Tests to ensure the assembly object can be converted to json properly """ w = generate_widget() w.classification = None s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) assert w2.to_json() == s assert w2.line_id == "1"
def test_widget(self): """ Tests to ensure the object can be converted to json properly """ w = generate_widget() s = w.to_json() assert (type(s) is str) w2 = Widget.from_json(s) assert (w.serial_number == w2.serial_number) w2_json = w2.to_json() assert (type(w2_json) is str) json_obj_version = json.loads(w2_json) assert (type(json_obj_version["classification"]["is_good"]) is bool)
def test_sql_interaction(self): w = generate_widget() db_cnxn = storcon.get_db_cxn() w.persist_sql(db_cnxn) assert (True)
def test_with_nones(self): w = generate_widget() w.telemetry = None w.classification = None s = w.to_json() assert (type(s) is str)
def test_many_widgets_to_json(self): widgets = [generate_widget().to_json() for i in range(0, 10)] js = json.dumps(widgets) assert (type(js) is str)
def test_pre_process(self): classifier = WidgetClassifier() classifier.load_model() widget = generate_widget() processed = classifier.pre_process(widget) assert (processed.shape == (1, 10, 5))