コード例 #1
0
 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")
コード例 #2
0
ファイル: surround_test.py プロジェクト: Aamir185/SurroundAI
 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")
コード例 #3
0
 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)
コード例 #4
0
ファイル: surround_test.py プロジェクト: Aamir185/SurroundAI
 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)
コード例 #5
0
    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)
コード例 #6
0
    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)
コード例 #7
0
        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)
コード例 #8
0
ファイル: main.py プロジェクト: Aamir185/SurroundAI

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)
コード例 #9
0
 def test_assembler_init_fail(self):
     assembler = Assembler("Fail test").set_stages(
         [InputValidator(), BadFilter(),
          HelloStage()])
     self.assertFalse(assembler.init_assembler())
コード例 #10
0
 def test_assembler_init_pass(self):
     assembler = Assembler("Pass test").set_stages(
         [InputValidator(), HelloStage()])
     self.assertTrue(assembler.init_assembler())
コード例 #11
0
ファイル: surround_test.py プロジェクト: mpej/surround
 def test_assembler_init_fail(self):
     assembler = Assembler("Fail test").set_validator(InputValidator())
     assembler.set_estimator(HelloStage(), [BadFilter()])
     self.assertFalse(assembler.init_assembler())
コード例 #12
0
ファイル: surround_test.py プロジェクト: mpej/surround
 def test_assembler_init_pass(self):
     assembler = Assembler("Pass test").set_validator(
         InputValidator()).set_estimator(HelloStage())
     self.assertTrue(assembler.init_assembler())