def test_populate_with_not_strict(self):
     tokens = {'UNIT_TEST': 'FOOBAR'}
     string = 'Unit {UNIT_TEST} {FAIL} Test'
     expect = 'Unit FOOBAR {FAIL} Test'
     result = utils.populate_with_tokens(
         string, tokens,
         left_wrapper='{', right_wrapper='}',
         strict=False)
     self.assertEquals(result, expect)
Example #2
0
    def replace_path_tokens(self, path, tokens):
        """Search and replace `%xxx%` with values from tokens.

        Used to replace any values of `%xxx%` with `'xxx`' from tokens. Can
        replace one, or many fields at aonce.

        :param str path: String of the path
        :param dict tokens: A dictionary of tokens to search through.
        :return: A modified string
        """
        if not path:
            return

        try:
            path = utils.populate_with_tokens(path, tokens)
        except LookupError as e:
            msg = 'Path (%s), tokens: (%s) error: %s' % (path, tokens, e)
            raise TypeError(msg)

        return path
Example #3
0
    def replace_path_tokens(self, path, tokens):
        """Search and replace `%xxx%` with values from tokens.

        Used to replace any values of `%xxx%` with `'xxx`' from tokens. Can
        replace one, or many fields at aonce.

        :param str path: String of the path
        :param dict tokens: A dictionary of tokens to search through.
        :return: A modified string
        """
        if not path:
            return

        try:
            path = utils.populate_with_tokens(path, tokens)
        except LookupError as e:
            msg = 'Path (%s), tokens: (%s) error: %s' % (path, tokens, e)
            raise TypeError(msg)

        return path
 def test_populate_with_env_with_non_string_tokens(self):
     tokens = {'foo': False}
     string = 'Unit test'
     result = utils.populate_with_tokens(string, tokens)
     self.assertEquals(result, string)
 def test_populate_with_env_with_missing_variables(self):
     os.environ['UNIT_TEST'] = 'FOOBAR'
     string = 'Unit %UNIT_TEST% Test %NOTFOUNDVARIABLE%'
     with self.assertRaises(LookupError):
         utils.populate_with_tokens(string, os.environ)
 def test_populate_with_bogus_data_OK(self):
     tokens = {'UNIT_TEST': {'foobar': 'bat'}}
     string = 'Unit %UNIT_TEST% Test'
     expect = 'Unit %UNIT_TEST% Test'
     result = utils.populate_with_tokens(string, tokens, strict=False)
     self.assertEquals(result, expect)
 def test_populate_with_bool(self):
     tokens = {'UNIT_TEST': True}
     string = 'Unit %UNIT_TEST% Test'
     expect = 'Unit True Test'
     result = utils.populate_with_tokens(string, tokens)
     self.assertEquals(result, expect)
 def test_populate_with_unicode_env(self):
     tokens = {'UNIT_TEST': u'FOOBAR'}
     string = 'Unit %UNIT_TEST% Test'
     expect = 'Unit FOOBAR Test'
     result = utils.populate_with_tokens(string, tokens)
     self.assertEquals(result, expect)