def test_rejecting_attributes(self): data = AssemblerState() assembler = Assembler("Reject attribute").set_stages( [InputValidator(), HelloStage()]).set_config(Config()) assembler.init_assembler() assembler.run(data) self.assertRaises(AttributeError, getattr, data, "no_text")
def test_rejecting_attributes(self): data = BasicData() assembler = Assembler("Reject attribute", ValidateData(), HelloStage(), Config()) assembler.init_assembler() assembler.run(data) self.assertRaises(AttributeError, getattr, data, "no_text")
def test_happy_path(self): data = AssemblerState() assembler = Assembler("Happy path").set_stages( [InputValidator(), HelloStage()]).set_config(Config()) assembler.init_assembler() assembler.run(data) self.assertEqual(data.text, test_text)
def test_happy_path(self): data = BasicData() assembler = Assembler("Happy path", ValidateData(), HelloStage(), Config()) assembler.init_assembler() assembler.run(data) self.assertEqual(data.text, test_text)
def test_finaliser_successful_pipeline(self): data = AssemblerState() assembler = Assembler("Finalizer test", InputValidator(), HelloStage(), Config()) assembler.set_finaliser(TestFinalStage()) assembler.init_assembler() # Run assembler which will succeed assembler.run(data) # Finalizer should be executed self.assertTrue(data.final_ran)
def test_finaliser_fail_pipeline(self): # Ensure pipeline will crash data = AssemblerState() data.text = "" assembler = Assembler("Finalizer test", InputValidator(), HelloStage(), Config()) assembler.set_finaliser(TestFinalStage()) assembler.init_assembler() # Run assembler which will fail assembler.run(data) # Finalizer should still be executed self.assertTrue(data.final_ran)
print("No training implemented") class AssemblerState(State): text = None class InputValidator(Stage): def operate(self, state, config): if state.text: raise ValueError("'text' is not None") if __name__ == "__main__": logging.basicConfig(level=logging.INFO) dir_extension = os.path.dirname(__file__) if dir_extension not in os.getcwd(): prefix = dir_extension + "/" app_config = Config() app_config.read_config_files([prefix + "config.yaml"]) data = AssemblerState() assembler = Assembler("Init state example").set_stages( [InputValidator(), HelloWorld()]).set_config(app_config) assembler.init_assembler() assembler.run(data) print("Text is '%s'" % data.text)
class BasicData(SurroundData): training_message = None text = None class Formatter(Visualiser): def visualise(self, surround_data, config): print("Visualiser result: %s" % surround_data.training_message) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) data = BasicData() assembler = Assembler("Training example", ValidateData(), HelloWorld()) assembler.init_assembler(True) assembler.set_visualiser(Formatter()) # Run assembler before training assembler.run(data) print("Text before training is '%s'" % data.text) data.text = None # Clear text to prevent validation raising error # Run training mode assembler.run(data, True) # Run assembler after training assembler.run(data) print("Text after training is '%s'" % data.text)
def test_assembler_init_fail(self): assembler = Assembler("Fail test").set_stages( [InputValidator(), BadFilter(), HelloStage()]) self.assertFalse(assembler.init_assembler())
def test_assembler_init_pass(self): assembler = Assembler("Pass test").set_stages( [InputValidator(), HelloStage()]) self.assertTrue(assembler.init_assembler())
def test_assembler_init_fail(self): assembler = Assembler("Fail test").set_validator(InputValidator()) assembler.set_estimator(HelloStage(), [BadFilter()]) self.assertFalse(assembler.init_assembler())
def test_assembler_init_pass(self): assembler = Assembler("Pass test").set_validator( InputValidator()).set_estimator(HelloStage()) self.assertTrue(assembler.init_assembler())