def empty_project_test(self):
        ent = load_document(
            make_data_filename('empty-project-config.xml').open('r'))

        assert ent.what == 'project'
        assert ent.name == 'Unit Test'
        assert len(ent.parameters) == 0
        assert len(ent.build_runners) == 0
class get_parameter_tester:
    @argv('get', 'param', 'test',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def not_existed_param_test(self, capfd):
        cli()
        out, err = capfd.readouterr()
        assert len(out.strip()) == 0
        assert len(err.strip()) == 0

    @argv('--fail-if-missed', 'get', 'param', 'test',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def fail_if_not_existed_param_test(self, capfd, expected_err):
        cli()
        out, err = capfd.readouterr()
        assert len(out.strip()) == 0
        assert expected_err == err.strip()

    @argv('get', 'param', 'empty-value',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def empty_value_test(self, capfd):
        cli()
        out, err = capfd.readouterr()
        assert len(out.strip()) == 0
        assert len(err.strip()) == 0

    @argv('get', 'param', 'some-param',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def non_empty_value_test(self, capfd):
        cli()
        out, err = capfd.readouterr()
        assert out.strip() == 'some-value'
        assert len(err.strip()) == 0

    @argv('get', 'param', 'multiline',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_value_test(self, capfd):
        cli()
        out, err = capfd.readouterr()
        assert out.strip() == 'some\ntest\nvalue'
        assert len(err.strip()) == 0
    def multiline_params_project_test(self):
        ent = load_document(
            make_data_filename('multiline-params-project-config.xml').open(
                'r'))

        params = ent.parameters

        assert len(params) == 3
        assert params['some-param'].value == 'some-value'
        assert params['multiline'].value == 'some\ntest\nvalue'
        assert params['empty-param'].value == ''
Beispiel #4
0
 def get_bool_value_test(self):
     cfg = Config(make_data_filename('sample.conf'))
     assert cfg.get_bool('not-existed') is None
     assert cfg.get_bool('not-existed', True) == True
     assert cfg.get_bool('not-existed', False) == False
     assert cfg.get_bool('true-bool-key-1') == True
     assert cfg.get_bool('false-bool-key-1') == False
     assert cfg.get_bool('true-bool-key-2') == True
     assert cfg.get_bool('false-bool-key-2') == False
     with pytest.raises(ValueError):
         cfg.get_bool('some-int')
Beispiel #5
0
    def ordering_test(self, capfd, expected_out):
        c = config(make_data_filename('ordering-test.yaml'))

        assert c['zero'] == 0
        assert c['uno'] == 1

        print(c)

        stdout, stderr = capfd.readouterr()

        assert expected_out == stdout
class application_tester:
    @argv('--help')
    @pytest.mark.usefixtures('prepare_cli')
    def help_test(self, capfd):
        cli()

        out, err = capfd.readouterr()
        assert 'Usage:' in out

    @argv('invalid-command')
    @pytest.mark.usefixtures('prepare_cli')
    def invalid_command_test(self, capfd):
        cli()

        out, err = capfd.readouterr()
        assert 'Error: No such command "invalid-command".' in err

    @argv('get', 'param', 'whatever', 'not-existed-file')
    @pytest.mark.usefixtures('prepare_cli')
    def not_existed_file_test(self, capfd):
        cli()

        out, err = capfd.readouterr()
        assert 'Error: Invalid value for "input": Could not open file: not-existed-file: No such file or directory' in err

    @argv('get', 'param', 'whatever', str(make_data_filename('empty.file')))
    @pytest.mark.usefixtures('prepare_cli')
    def invlalid_input_test_1(self, capfd):
        cli()

        out, err = capfd.readouterr()
        assert 'Error: XML syntax error: Document is empty' in err

    @argv('get', 'param', 'whatever',
          str(make_data_filename('just-a-text.file')))
    @pytest.mark.usefixtures('prepare_cli')
    def invlalid_input_test_2(self, capfd):
        cli()

        out, err = capfd.readouterr()
        assert 'Error: XML syntax error: Start tag expected' in err
    def config_test(self):
        system_conf = omfcore.config(make_data_filename('system.conf'))
        user_conf = omfcore.config(make_data_filename('user.conf'))

        assert system_conf.pattern == 'satu'
        assert isinstance(system_conf.patterns, dict)
        assert len(system_conf.patterns) == 2

        assert user_conf.pattern == 'dua'
        assert isinstance(user_conf.patterns, dict)
        assert len(user_conf.patterns) == 2

        user_conf.merge_from(system_conf)

        assert system_conf.pattern == 'satu'
        assert len(system_conf.patterns) == 2
        assert system_conf.patterns['one'] == 'satu'
        assert system_conf.patterns['two'] == 'two'

        assert user_conf.pattern == 'dua'
        assert len(user_conf.patterns) == 3
        assert user_conf.patterns['one'] == 'satu'
        assert user_conf.patterns['two'] == 'dua'
        assert user_conf.patterns['three'] == 'tiga'
Beispiel #8
0
class remove_all_parameters_tester:
    @argv('del', 'params', 'all',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def delete_all_params_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('del', 'params', 'blah.*',
          str(make_data_filename('many-similar-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def delete_blah_params_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('del', 'params', '*.test.*',
          str(make_data_filename('many-similar-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def delete_star_test_star_params_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('del', 'params', '*.*e',
          str(make_data_filename('many-similar-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def delete_star_star_e_params_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0
Beispiel #9
0
 def get_color_value_test(self):
     cfg = Config(make_data_filename('sample.conf'))
     assert cfg.get_color('red', 'red') == '\x1b[0m\x1b[31m'
     assert cfg.get_color('red', 'red', with_reset=False) == '\x1b[31m'
     assert cfg.get_color('error', 'normal') == '\x1b[0m\x1b[31m\x1b[1m'
     assert cfg.get_color('error', 'normal', with_reset=False) == '\x1b[31m\x1b[1m'
     assert cfg.get_color('not-existed', 'normal') == '\x1b[0m\x1b[38m'
     assert cfg.get_color('some-int', 'reset') == '\x1b[0m\x1b[38;5;123m'
     assert cfg.get_color('none', 'none') == ''
     # Try TrueColor specs
     assert cfg.get_color('true_rgb_red', 'red') == '\x1b[0m\x1b[38;2;255;0;0m'
     assert cfg.get_color('true_rgb_green', 'red') == '\x1b[0m\x1b[38;2;0;255;0m'
     assert cfg.get_color('true_rgb_blue', 'red') == '\x1b[0m\x1b[38;2;0;0;255m'
     with pytest.raises(TypeError):
         cfg.get_color('red')
    def build_runners_test(self, capfd, expected_out):
        ent = load_document(
            make_data_filename('sample-build-template.xml').open('r'))

        runners = ent.build_runners

        assert len(runners) == 1

        # Check interation protocol
        for runner in runners:
            print('runner(repr): {}'.format(repr(runner)))
            print('runner(str): {}'.format(str(runner)))

        runner = runners[0]

        # - iterate over dict of key-value pairs
        for k, v in runner.parameters.items():
            print('{}={}'.format(k, v))

        out, err = capfd.readouterr()
        assert expected_out == out.strip()
Beispiel #11
0
 def not_exitsted_file_test(self):
     cfg = Config(make_data_filename('not-existed-file'))
     assert cfg.get_string('not-existed', 'default') == 'default'
     assert cfg.get_int('not-existed', 123) == 123
 def setup(self):
     self.na = make_data_filename('non_accessible.conf')
     self.na.chmod(0)
Beispiel #13
0
class add_parameter_tester:
    @argv('add', 'param', 'test', 'test-value',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def to_empty_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'test', 'test-value',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def to_non_empty_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'some-param', 'new-value',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def replace_value_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'param-with-spec', 'new-value',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def replace_value_of_spec_param_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'empty-param', 'now-non-empty',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def replace_empty_value_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'empty-param', '"now-quoted-non-empty"',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def add_quoted_value_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', '--', 'empty-param', '-now-quoted-non-empty',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def add_leading_dash_and_spaces_value_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'test', 'some\ntest\nvalue',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_1(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'new-param', 'some\ntest\nvalue',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_2(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'some-param', 'some\ntest\nvalue',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_3(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'param-with-spec', 'some\ntest\nvalue',
          str(make_data_filename('non-empty-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_4(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'new-param', 'some\ntest\nvalue',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_5(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'some-param', 'some\ntest\nvalue',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_6(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()

    @argv('add', 'param', 'multiline', 'some\ntest\nvalue',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_param_test_7(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
    def non_empty_project_test(self, capfd, expected_out):
        ent = load_document(
            make_data_filename('non-empty-params-project-config.xml').open(
                'r'))

        params = ent.parameters

        # check __len__
        assert len(params) == 3

        # check iteration protocol
        # - iterate over list of parameters
        for param in params:
            print('param(repr): {}'.format(repr(param)))
            print('param(str): {}'.format(str(param)))

        # - iterate over dict of key-value pairs
        for k, v in params.items():
            print('{}={}'.format(k, v))

        # - iterate over parameter names
        for k in params.keys():
            print('{}'.format(k))

        # check __contains__
        assert 'some-param' in params
        assert 'unknown' not in params

        # check __getitem__
        some = params['some-param']
        assert some.name == 'some-param'
        assert some.value == 'some-value'

        with pytest.raises(KeyError):
            params['unknown']

        # check __setitem__
        # - update existed
        params['some-param'] = 'new-value'
        some = params['some-param']
        assert some.value == 'new-value'

        # check `parameter` conversion to `tuple`
        assert len(some) == 2
        kvp = tuple(some)
        assert kvp[0] == 'some-param'
        assert kvp[1] == 'new-value'

        # check value assign to `parameter`
        some.value = 'new-new-value'

        # check `name` constantness
        with pytest.raises(AttributeError) as ex:
            some.name = 'new'
        assert "can't set attribute" in str(ex)

        # check __setitem__
        # - add a new one
        params['unknown'] = 'now-is-known'
        assert 'unknown' in params
        assert len(params) == 4

        # check __delitem__
        del params['unknown']
        assert len(params) == 3

        out, err = capfd.readouterr()
        assert expected_out == out.strip()
Beispiel #15
0
class rename_parameter_tester:
    @argv('rename', 'param', 'old', 'new',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def in_empty_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('--fail-if-missed', 'rename', 'param', 'old', 'new',
          str(make_data_filename('empty-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def failure_in_empty_project_test(self, capfd, expected_err):
        cli()
        out, err = capfd.readouterr()
        assert expected_err == err.strip()
        assert len(out.strip()) == 0

    @argv('rename', 'param', 'empty-param', 'new-empty-param',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def empty_value_rename_in_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('rename', 'param', 'some-param', 'new-some-param',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def trivial_rename_in_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('rename', 'param', 'multiline', 'new-multiline',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def multiline_rename_in_project_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0

    @argv('rename', 'param', 'multiline', 'empty-param',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def rename_try_override_test(self, capfd, expected_err):
        cli()
        out, err = capfd.readouterr()
        assert len(out.strip()) == 0
        assert expected_err == err.strip()

    @argv('rename', 'param', '--force', 'multiline', 'empty-param',
          str(make_data_filename('multiline-params-project-config.xml')))
    @pytest.mark.usefixtures('prepare_cli')
    def rename_force_override_test(self, capfd, expected_out):
        cli()
        out, err = capfd.readouterr()
        assert expected_out == out.strip()
        assert len(err.strip()) == 0
Beispiel #16
0
 def get_int_value_test(self):
     cfg = Config(make_data_filename('sample.conf'))
     assert cfg.get_int('some-int') == 123
     assert cfg.get_int('not-existed', 123) == 123
     with pytest.raises(ValueError):
         cfg.get_int('not-an-int', 123)
Beispiel #17
0
    def empty_test(self):
        c = config(make_data_filename('empty.yaml'))

        assert len(c) == 0
def try_read_contents(filename):
    input_file = make_data_filename(filename)
    if input_file.exists():
        with input_file.open('r') as fd:
            return fd.read().strip()
    raise RuntimeError('File not found: {}'.format(input_file))
Beispiel #19
0
    def not_a_dict_file_test(self):
        with pytest.raises(ValueError) as ex:
            c = config(make_data_filename('not-a-dict.yaml'))

        assert 'Config file expected to be a YAML dictionary, but it does not: `' in str(
            ex)
Beispiel #20
0
 def get_string_value_test(self):
     cfg = Config(make_data_filename('sample.conf'))
     assert cfg.get_string('some') == 'value'
     assert cfg.get_string('not-existed', 'default') == 'default'
     assert cfg.get_string('some-int') == '123'
 def setup(self):
     self.na = make_data_filename('non-accessable.flac')
     self.na.chmod(0)