Exemplo n.º 1
0
    def test_config_gets_values_like_attributes(self):
        '''Make sure the options we set can be retrieved like values'''
        config = Config()
        config.setup({"a": 1, "b": 2, "c-d": 3})

        config.a | should | be(1)
        config.b | should | be(2)
        config.c_d | should | be(3)
Exemplo n.º 2
0
    def test_config_gets_values_like_attributes(self):
        '''Make sure the options we set can be retrieved like values'''
        config = Config()
        config.setup({"a": 1, "b": 2, "c-d": 3})

        config.a | should | be(1)
        config.b | should | be(2)
        config.c_d | should | be(3)
Exemplo n.º 3
0
    def test_it_uses_extractor_if_provided(self):
        '''If given an extractor, it applies extractor to the options before setting them'''
        template = fudge.Fake("template")
        def extractor(template, options):
            for key, val in options.items():
                yield key, val + 1

        config = Config(template)
        config.setup({'a':1, 'b':2}, extractor=extractor)
        config._util.values |should| equal_to({'a':2, 'b':3})
Exemplo n.º 4
0
    def test_config_gets_attributes_from_util(self):
        '''__getattr__ on Config uses values from util'''
        key = 'my_awesome_key'
        val = fudge.Fake("val")

        util = fudge.Fake("util").expects("find_value").with_args(key).returns(val)
        config = Config()
        config._util = util

        getattr(config, key) |should| be(val)
Exemplo n.º 5
0
 def test_it_overwrites_config_file_with_options(self):
     '''It gets values from a config file'''
     contents = """
         { "a" : 1
         , "b" : 2
         }
     """
     with a_temp_file(contents) as filename:
         config = Config()
         config.setup({"config-file":filename, "a":4})
         config._util.values |should| equal_to({"config_file":filename, "a":4, u"b":2})
Exemplo n.º 6
0
 def test_it_gets_values_from_config_file(self):
     '''It gets values from a config file'''
     contents = """
         { "a" : 1
         , "b" : 2
         }
     """
     with a_temp_file(contents) as filename:
         config = Config()
         config.setup({"config-file":filename})
         config._util.values |should| equal_to({"config_file":filename, u"a":1, u"b":2})
Exemplo n.º 7
0
    def test_it_uses_extractor_if_provided(self):
        '''If given an extractor, it applies extractor to the options before setting them'''
        template = fudge.Fake("template")

        def extractor(template, options):
            for key, val in options.items():
                yield key, val + 1

        config = Config(template)
        config.setup({'a': 1, 'b': 2}, extractor=extractor)
        config._util.values | should | equal_to({'a': 2, 'b': 3})
Exemplo n.º 8
0
    def test_config_gets_attributes_from_util(self):
        '''__getattr__ on Config uses values from util'''
        key = 'my_awesome_key'
        val = fudge.Fake("val")

        util = fudge.Fake("util").expects("find_value").with_args(key).returns(
            val)
        config = Config()
        config._util = util

        getattr(config, key) | should | be(val)
Exemplo n.º 9
0
    def test_setup_uses_util(self, FakeConfigUtil):
        '''It uses self._util in setup'''
        options = fudge.Fake("options")
        template = fudge.Fake("template")
        extractor = fudge.Fake("extractor")
        util = (fudge.Fake("util").remember_order().expects(
            "use_options").with_args(options,
                                     extractor).expects("use_config_file"))

        FakeConfigUtil.expects_call().with_args(template).returns(util)
        config = Config(template)
        config.setup(options, extractor=extractor)
Exemplo n.º 10
0
    def test_setup_uses_util(self, FakeConfigUtil):
        '''It uses self._util in setup'''
        options = fudge.Fake("options")
        template = fudge.Fake("template")
        extractor = fudge.Fake("extractor")
        util = (fudge.Fake("util").remember_order()
                .expects("use_options").with_args(options, extractor)
                .expects("use_config_file")
                )

        FakeConfigUtil.expects_call().with_args(template).returns(util)
        config = Config(template)
        config.setup(options, extractor=extractor)
Exemplo n.º 11
0
 def test_it_overwrites_config_file_with_options(self):
     '''It gets values from a config file'''
     contents = """
         { "a" : 1
         , "b" : 2
         }
     """
     with a_temp_file(contents) as filename:
         config = Config()
         config.setup({"config-file": filename, "a": 4})
         config._util.values | should | equal_to({
             "config_file": filename,
             "a": 4,
             u"b": 2
         })
Exemplo n.º 12
0
 def test_it_gets_values_from_config_file(self):
     '''It gets values from a config file'''
     contents = """
         { "a" : 1
         , "b" : 2
         }
     """
     with a_temp_file(contents) as filename:
         config = Config()
         config.setup({"config-file": filename})
         config._util.values | should | equal_to({
             "config_file": filename,
             u"a": 1,
             u"b": 2
         })
Exemplo n.º 13
0
def register_from_options(options=None, template=None, extractor=None):
    """Register the spec codec using the provided options"""
    if template is None:
        from noseOfYeti.plugins.support.spec_options import spec_options as template

    if extractor is None:
        from noseOfYeti.plugins.support.spec_options import extract_options_dict as extractor

    config = Config(template)
    config.setup(options, extractor)

    imports = determine_imports(
        extra_imports=';'.join([d for d in config.extra_import if d]),
        with_default_imports=config.with_default_imports)

    tok = Tokeniser(default_kls=config.default_kls,
                    import_tokens=imports,
                    wrapped_setup=config.wrapped_setup,
                    with_describe_attrs=not config.no_describe_attrs)

    TokeniserCodec(tok).register()
Exemplo n.º 14
0
def register_from_options(options=None, template=None, extractor=None):
    """Register the spec codec using the provided options"""
    if template is None:
        from noseOfYeti.plugins.support.spec_options import spec_options as template

    if extractor is None:
        from noseOfYeti.plugins.support.spec_options import extract_options_dict as extractor

    config = Config(template)
    config.setup(options, extractor)

    imports = determine_imports(
          extra_imports = ';'.join([d for d in config.extra_import if d])
        , with_default_imports = config.with_default_imports
        )

    tok = Tokeniser(
          default_kls = config.default_kls
        , import_tokens = imports
        , wrapped_setup = config.wrapped_setup
        , with_describe_attrs = not config.no_describe_attrs
        )

    TokeniserCodec(tok).register()
Exemplo n.º 15
0
 def test_it_updates_values_with_options(self):
     # With no values to begin with
     config = Config()
     config._util.values | should | equal_to({})
     config.setup({'a': 1, 'b': 2})
     config._util.values | should | equal_to({'a': 1, 'b': 2})
Exemplo n.º 16
0
 def test_it_updates_values_with_options(self):
     # With no values to begin with
     config = Config()
     config._util.values | should | equal_to({})
     config.setup({'a': 1, 'b': 2})
     config._util.values | should | equal_to({'a': 1, 'b': 2})