def test_running() -> None:
    context = AlgorithmContext(random_string(10), MyDataProvider(), cycles=1)
    context.start()
    assert MyDataProvider.cycles == 1

    context = AlgorithmContext(random_string(10), MyDataProvider(), cycles=2)
    context.start()
    assert MyDataProvider.cycles == 3
def test_data_provider_registration() -> None:
    context = AlgorithmContext(random_string(10), MyDataProvider())

    assert context.data_provider is not None
    assert isinstance(context.data_provider, MyDataProvider)

    with pytest.raises(Exception) as exc_info:
        AlgorithmContext(random_string(10), MyDataProvider)

    assert str(exc_info.value) == 'Data provider must be an instance ' \
                                  'of the AbstractDataProvider class'
Exemplo n.º 3
0
def test_registration() -> None:
    data_provider = MyDataProvider()
    data_provider_two = MyDataProviderTwo()

    algorithm_context = AlgorithmContext(random_string(10), data_provider)
    algorithm_context_two = AlgorithmContext(random_string(10),
                                             data_provider_two)
    orchestrator = Orchestrator()
    orchestrator.register_algorithm(algorithm_context)
    orchestrator.register_algorithm(algorithm_context_two)

    assert orchestrator.registered_algorithms == [
        algorithm_context, algorithm_context_two
    ]
def test_config_registration() -> None:
    config = AlgorithmContextConfiguration()
    context = AlgorithmContext(random_string(10),
                               MyDataProvider(),
                               config=config)
    assert context.config is not None
    assert context.config == config
Exemplo n.º 5
0
    def test_deleting(self) -> None:
        assert len(self.MyModel.query.all()) == 0

        test_model_one = self.MyModel(name=random_string(10))
        test_model_two = self.MyModel(name=random_string(10))
        test_model_one.save()
        test_model_two.save()

        assert len(self.MyModel.query.all()) == 2

        test_model_two.delete()

        assert len(self.MyModel.query.all()) == 1

        test_model_one.delete()

        assert len(self.MyModel.query.all()) == 0
        self.db.session.commit()
Exemplo n.º 6
0
    def test_creating(self):
        assert len(self.MyModel.query.all()) == 0

        test_model_one = self.MyModel(name=random_string(10))

        assert len(self.MyModel.query.all()) == 0

        test_model_one.save()

        assert len(self.MyModel.query.all()) == 1

        test_model_two = self.MyModel(name=random_string(10))

        assert len(self.MyModel.query.all()) == 1

        test_model_two.save()

        assert len(self.MyModel.query.all()) == 2
        self.db.session.commit()
Exemplo n.º 7
0
    def test_deleting(self) -> None:
        self.db.initialize_tables()
        assert len(self.CustomModel.query.all()) == 0

        test_model_one = self.CustomModel(name=random_string(10))
        test_model_two = self.CustomModel(name=random_string(10))
        test_model_one.save()
        test_model_two.save()

        assert len(self.CustomModel.query.all()) == 2

        test_model_two.delete()

        assert len(self.CustomModel.query.all()) == 1

        test_model_one.delete()

        assert len(self.CustomModel.query.all()) == 0
        self.db.session.commit()
def test_initializer_registration() -> None:
    initializer = MyInitializer()
    context = AlgorithmContext(random_string(10), MyDataProvider(),
                               initializer)
    assert context.initializer is not None
    assert context.initializer is initializer

    context = AlgorithmContext(random_string(10), MyDataProvider())
    context.set_algorithm_context_initializer(initializer)

    assert context.initializer is not None
    assert context.initializer is initializer

    # Check exceptions
    with pytest.raises(AssertionError) as exc_info:
        context = AlgorithmContext(random_string(10), MyDataProvider())
        context.set_algorithm_context_initializer(MyInitializer)

    assert str(exc_info.value) == 'Initializer must be an instance of ' \
                                  'AlgorithmContextInitializer'
Exemplo n.º 9
0
    def test_updating(self) -> None:
        assert len(self.MyModel.query.all()) == 0

        test_model_one = self.MyModel(name=random_string(10))
        test_model_two = self.MyModel(name=random_string(10))
        test_model_one.save()
        test_model_two.save()

        model_one_name = test_model_two.name
        self.db.session.commit()

        assert len(self.MyModel.query.all()) == 2

        test_model_one.update(name=random_string(10))

        test_model_one.save()

        self.db.session.commit()

        assert model_one_name != test_model_one.name
Exemplo n.º 10
0
def test() -> None:
    config = AlgorithmContextConfiguration()
    config.load_settings_module('tests.resources.settings')

    assert config[BASE_DIR] is not None
    assert config[DATABASE_CONFIG] is not None

    database_config = config[DATABASE_CONFIG]

    assert database_config[DATABASE_TYPE] is not None
    assert database_config[DATABASE_NAME] is not None
    assert database_config[DATABASE_DIRECTORY_PATH] is not None

    new_attribute = random_string(10)
    new_attribute_value = random_string(10)

    config.set(new_attribute, new_attribute_value)

    assert config[new_attribute] is not None
    assert config[new_attribute] == new_attribute_value

    with pytest.raises(Exception):
        config.set(new_attribute, random_string(10))
    def setup_method(self, test_method):
        # Create temp csv file
        self.csv_path = os.path.join('/tmp', random_string(10) + '.csv')
        os.mknod(self.csv_path)

        records = 200
        fieldnames = ['id', 'name', 'age', 'city']
        names = ['Deepak', 'Sangeeta', 'Geetika', 'Anubhav', 'Sahil', 'Akshay']
        cities = ['Delhi', 'Kolkata', 'Chennai', 'Mumbai']

        # Open file in append mode
        with open(self.csv_path, 'w', newline='') as write_obj:
            # Create a writer object from csv module
            dict_writer = csv.DictWriter(write_obj, fieldnames=fieldnames)

            for i in range(0, records):
                dict_writer.writerow(
                    dict([('id', i), ('name', random.choice(names)),
                          ('age', str(random.randint(24, 26))),
                          ('city', random.choice(cities))]))