예제 #1
0
def test_entrypoint_handle_retrieve_files():
    """Tests entrypoint's handle_retrieve_files function by passing in an empty class instances"""
    entry = entrypoint.__internal__()
    result = entry.handle_retrieve_files(
        environment.Environment(configuration.Configuration()),
        argparse.Namespace(), [])
    assert result is None
예제 #2
0
def test_entrypoint_handle_check_continue_parse_continue_result():
    """Tests entrypoint's handle_check_continue and parse_continue_result functions by passing in empty class
     instances"""
    entry = entrypoint.__internal__()
    result = entry.handle_check_continue(
        algorithm.Algorithm(),
        environment.Environment(configuration.Configuration()), {})
    assert result == {}
예제 #3
0
def test_entrypoint_do_work():
    """Tests entrypoint's do_work function by passing in empty parameters"""
    try:
        parser = argparse.ArgumentParser()
        result = entrypoint.do_work(parser, configuration.Configuration(),
                                    algorithm.Algorithm())
        assert result == {}
    except RuntimeError as runtime_error:
        assert str(runtime_error) == "The Algorithm class method perform_process()" \
                                     " must be overridden by a derived class"
예제 #4
0
def test_environment_environment():
    """Tests initializing environment's Environment class by making sure it contains all necessary parameters"""
    environ = environment.Environment(configuration.Configuration())
    assert environ.sensor is None
    assert environ.args is None
    for entry in ['transformer_version', 'transformer_description', 'transformer_name', 'transformer_sensor',
                  'transformer_type', 'author_name', 'author_email', 'contributors', 'repository']:
        assert hasattr(environ.configuration, entry)
        if entry == 'contributors':
            assert getattr(environ.configuration, entry) == []
        else:
            assert getattr(environ.configuration, entry) is None
예제 #5
0
def test_algorithm():
    """Tests initializing the algorithm.Algorithm() class within agpypeline and performing a process with default
    parameters """
    alg = algorithm.Algorithm()
    try:
        res = alg.perform_process(
            environment.Environment(configuration.Configuration()), {}, {}, [])
    except RuntimeError as error:
        assert str(
            error
        ) == "The Algorithm class method perform_process() must be overridden by a derived class"
    else:
        assert isinstance(res, dict)
예제 #6
0
def test_configuration():
    """Tests agpypeline's configuration.Configuration() class by initializing configuration.Configuration() and
     checking to make sure that all necessary parameters are contained"""
    config = configuration.Configuration()
    for entry in [
            'transformer_version', 'transformer_description',
            'transformer_name', 'transformer_sensor', 'transformer_type',
            'author_name', 'author_email', 'contributors', 'repository'
    ]:
        assert hasattr(config, entry)
        if entry == 'contributors':
            assert getattr(config, entry) == []
        else:
            assert getattr(config, entry) is None
예제 #7
0
def test_entrypoint_add_parameters():
    """Tests entrypoint's add_parameters function by passing in empty parameters"""
    with open("data/entrypoint_add_parameters.json", 'r',
              encoding='utf-8') as result_file:
        check_result = json.load(result_file)
    parser = argparse.ArgumentParser()
    entrypoint.add_parameters(
        parser, algorithm.Algorithm(),
        environment.Environment(configuration.Configuration()))
    try:
        args = parser.parse_args()
        for arg in vars(args):
            assert arg in check_result and check_result[arg] == getattr(
                args, arg)
    except SystemExit:
        assert False  # SystemExit exception was caught
예제 #8
0
def test_entrypoint_perform_processing():
    """Tests entrypoint's perform_processing function by passing in empty class instances"""
    namespace = argparse.Namespace()
    namespace.file_list = []
    namespace.working_space = []
    entry = entrypoint.__internal__()
    try:
        result = entry.perform_processing(
            environment.Environment(configuration.Configuration()),
            algorithm.Algorithm(), namespace, [])
    except RuntimeError as error:
        assert str(
            error
        ) == "The Algorithm class method perform_process() must be overridden by a derived class"
    else:
        assert result is not None
예제 #9
0
def test_environment_get_transformer_params():
    """Checks the call of get_transformer_parameters with default parameters against the output from a .json file
    list_files is set to None because it is a function, and timestamp is set to none because it is the current
     timestamp, which differs from second to second"""
    with open("data/environment_get_transformer_params.json", encoding='utf-8') as in_file:
        check_result = json.load(in_file)
    environ = environment.Environment(configuration.Configuration())
    namespace = argparse.Namespace()
    namespace.file_list = []
    namespace.working_space = []
    result = environ.get_transformer_params(namespace, [])
    result_dict = {'transformer_md': result['transformer_md'], 'full_md': result['full_md']}
    check_md = dict(result['check_md']._asdict())
    check_md['timestamp'] = ''
    check_md['list_files'] = ''
    result_dict['check_md'] = check_md
    assert check_result == result_dict
예제 #10
0
def test_environment_add_parameters():
    """Tests the call of add_parameters with default parameters"""
    parser = argparse.ArgumentParser()
    environ = environment.Environment(configuration.Configuration())
    environ.add_parameters(parser)
    assert parser.epilog == "None version None author None None"
예제 #11
0
def test_environment_generate_transformer_md():
    """Tests the call of generate_transformer_md on a default configuration"""
    environ = environment.Environment(configuration.Configuration())
    assert environ.generate_transformer_md() == {'version': None, 'name': None, 'author': None, 'description': None,
                                                 'repository': {'repUrl': None}}