Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_module_default_rule(self):
input = dedent("""\
git module bar:
export: bar
""")
scope, imports = parse_string(input)
self.assertIn("bar", scope.modules)
module = scope.modules["bar"]
self.assertIsInstance(module, Module)
self.assertIsInstance(module.default_rule, Rule)
self.assertEqual(module.default_rule.export, "bar")
def test_parse_rule(self):
input = dedent("""\
rule foo:
export: out/
""")
scope, imports = parse_string(input)
self.assertIn("foo", scope.rules)
rule = scope.rules["foo"]
self.assertIsInstance(rule, Rule)
self.assertEqual(rule.name, "foo")
self.assertEqual(rule.export, "out/")
def extract_rules(blob):
rules = {}
for field in list(blob.keys()):
parts = field.split()
if len(parts) == 2 and parts[0] == "rule":
inner_blob = blob.pop(field) # remove the field from blob
name = parts[1]
rules[name] = rule.Rule(name, inner_blob)
return rules
if bad_keys:
raise RuntimeError("unknown module fields: {}".format(
", ".join(bad_keys)))
overlapping_names = rules.keys() & modules.keys()
if overlapping_names:
raise RuntimeError("rules and modules with the same name: " +
", ".join(overlapping_names))
self.fields = blob
self.rules = rules
self.modules = modules
self.name = name
self.remote = remote
if "rule" in self.fields:
self.default_rule = rule.Rule("", self.fields["rule"])
else:
self.default_rule = rule.Rule("", {})
field_names = {"imports", "rule"}
bad_keys = blob.keys() - field_names
if bad_keys:
raise RuntimeError("unknown module fields: {}".format(
", ".join(bad_keys)))
overlapping_names = rules.keys() & modules.keys()
if overlapping_names:
raise RuntimeError("rules and modules with the same name: " +
", ".join(overlapping_names))
self.fields = blob
self.rules = rules
self.modules = modules
self.name = name
self.remote = remote
if "rule" in self.fields:
self.default_rule = rule.Rule("", self.fields["rule"])
else:
self.default_rule = rule.Rule("", {})
raise ParserError(
textwrap.dedent('''\
The "build" field is no longer supported. If you need to
untar/unzip a curl module, use the "unpack" field.'''))
if 'files' in blob:
raise ParserError(
'The "files" field is no longer supported. Use "pick" instead.')
copy = _extract_multimap_field(blob, 'copy')
move = _extract_multimap_field(blob, 'move')
executable = _extract_optional_list_field(blob, 'executable')
drop = _extract_optional_list_field(blob, 'drop')
pick = _extract_optional_list_field(blob, 'pick')
export = typesafe_pop(blob, 'export', None)
if not any((copy, move, executable, drop, pick, export)):
return None
rule = Rule(name, copy, move, executable, drop, pick, export)
return rule