How to use the peru.parser.parse_string function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / tests / test_parser.py View on Github external
def test_build_field_deprecated_message(self):
        input = dedent('''\
            rule foo:
                build: shell command
            ''')
        try:
            parse_string(input)
        except ParserError as e:
            assert 'The "build" field is no longer supported.' in e.message
        else:
            assert False, 'expected ParserError'
github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_module(self):
        input = dedent("""\
            sometype module foo:
                url: http://www.example.com/
                rev: abcdefg
            """)
        scope, imports = parse_string(input)
        self.assertIn("foo", scope.modules)
        module = scope.modules["foo"]
        self.assertIsInstance(module, Module)
        self.assertEqual(module.name, "foo")
        self.assertEqual(module.type, "sometype")
        self.assertDictEqual(module.plugin_fields, {
            "url": "http://www.example.com/",
            "rev": "abcdefg"
        })
github buildinspace / peru / tests / test_parser.py View on Github external
def test_name_prefix(self):
        input = dedent('''\
            git module foo:
                url: fun stuff

            rule bar:
                export: more stuff
            ''')
        scope, imports = parse_string(input, name_prefix='x')
        # Lookup keys should be unaffected, but the names that modules and
        # rules give for themselves should have the prefix.
        assert scope.modules['foo'].name == 'xfoo'
        assert scope.rules['bar'].name == 'xbar'
github buildinspace / peru / tests / test_parser.py View on Github external
def test_bad_rule_name_throw(self):
        with self.assertRaises(ParserError):
            parse_string("rule foo bar:")
github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_multimap_imports(self):
        input = dedent('''\
            imports:
                foo:
                  - bar/
            ''')
        scope, imports = parse_string(input)
        self.assertDictEqual(scope.modules, {})
        self.assertDictEqual(scope.rules, {})
        self.assertEqual(imports, {'foo': ('bar/', )})
github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_empty_file(self):
        scope, imports = parse_string('')
        self.assertDictEqual(scope.modules, {})
        self.assertDictEqual(scope.rules, {})
        self.assertEqual(imports, {})
github buildinspace / peru / tests / test_parser.py View on Github external
def test_parse_toplevel_imports(self):
        input = dedent("""\
            imports:
                foo: bar/
            """)
        scope, imports = parse_string(input)
        self.assertDictEqual(scope.modules, {})
        self.assertDictEqual(scope.rules, {})
        self.assertEqual(imports, {'foo': ('bar/', )})
github buildinspace / peru / tests / test_parser.py View on Github external
def test_non_string_module_field_name(self):
        input = dedent('''\
            git module foo:
                12345: bar
            ''')
        try:
            parse_string(input)
        except ParserError as e:
            assert '12345' in e.message
        else:
            assert False, 'expected ParserError'
github buildinspace / peru / peru / module.py View on Github external
})
        if cache_key in runtime.cache.keyval:
            yaml = json.loads(runtime.cache.keyval[cache_key])
        else:
            try:
                yaml_bytes = await runtime.cache.read_file(
                    tree, self.peru_file)
                yaml = yaml_bytes.decode('utf8')
            except FileNotFoundError:
                yaml = None
            runtime.cache.keyval[cache_key] = json.dumps(yaml)
        if yaml is None:
            # This module is not a peru project.
            return (None, None)
        prefix = self.name + scope.SCOPE_SEPARATOR
        return parser.parse_string(yaml, name_prefix=prefix)
github buildinspace / peru / peru / module.py View on Github external
    @asyncio.coroutine
    def parse_peru_file(self, runtime):
        from . import parser  # avoid circular imports
        tree = yield from self._get_base_tree(runtime)
        try:
            yaml = runtime.cache.read_file(tree, self.peru_file)
        except FileNotFoundError:
            # This module is not a peru project.
            return (None, None)
        prefix = self.name + scope.SCOPE_SEPARATOR
        return parser.parse_string(yaml, name_prefix=prefix)