Beispiel #1
0
 def test_boolean(self):
     s = io.StringIO(
         '''"""docstring""" \n ___yes___ = True\n___no___=False''')
     output = read_metadata(s)
     self.assertEqual(output, {
         'doc': "docstring",
         'yes': True,
         'no': False
     })
Beispiel #2
0
 def test_complex_list(self):
     s = io.StringIO(
         '''"""docstring""" \n ___list___ = ["foo", True, [], [False, 'bar']]'''
     )
     output = read_metadata(s)
     self.assertEqual(output, {
         'doc': "docstring",
         'list': ["foo", True, [], [False, "bar"]]
     })
Beispiel #3
0
 def test_full_file(self):
     s = io.StringIO(
         '''"""docstring""" \n ___foo___="bar"\n___other___='whatever'\n\nimport xyz # some comment'''
     )
     output = read_metadata(s)
     self.assertEqual(output, {
         'doc': "docstring",
         'foo': 'bar',
         'other': 'whatever'
     })
Beispiel #4
0
def add_metadata(path, resources):
    for resource in resources.values():
        file = None
        if resource['type'] == "app":
            file = next(f for f in resource['files'] if "/main.py" in f)
        elif resource['type'] == "lib":
            file = next(iter(resource['files'].keys()))

        if file:
            try:
                with open(os.path.join(path, file), "r") as stream:
                    resource.update(_normalize_metadata(read_metadata(stream)))
            except ParseException as e:
                resource.setdefault("errors", []).append(file + ": " + str(e))
Beispiel #5
0
 def test_single_list_element(self):
     s = io.StringIO('''"""docstring""" \n ___list___ = ["foo"]''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "docstring", 'list': ["foo"]})
Beispiel #6
0
 def test_list_empty(self):
     s = io.StringIO('''"""docstring""" \n ___list___ = []''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "docstring", 'list': []})
Beispiel #7
0
 def test_invalid_boolean(self):
     s = io.StringIO('''"""docstring""" \n ___yes___ = TRUE''')
     with self.assertRaises(ParseException) as context:
         output = read_metadata(s)
     self.assertIn("Invalid boolean ('True' expected, 'TRUE' found)",
                   str(context.exception))
Beispiel #8
0
 def test_invalid_int(self):
     s = io.StringIO('''"""docstring""" \n ___int___ = 123k''')
     with self.assertRaises(ParseException) as context:
         output = read_metadata(s)
     self.assertIn("Invalid int: 123k", str(context.exception))
Beispiel #9
0
 def test_int(self):
     s = io.StringIO('''"""docstring""" \n ___int___ = 123''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "docstring", 'int': 123})
Beispiel #10
0
 def test_invalid_key_eof(self):
     s = io.StringIO('''"""docstring""" \n ___foobar''')
     with self.assertRaises(ParseException) as context:
         output = read_metadata(s)
     self.assertIn("Invalid key: ___foobar", str(context.exception))
Beispiel #11
0
 def test_docstring_only(self):
     s = io.StringIO('''"""bar"""''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "bar"})
Beispiel #12
0
 def test_invalid_string(self):
     s = io.StringIO('''"""docstring""" \n ___string___ = "bar''')
     with self.assertRaises(ParseException) as context:
         output = read_metadata(s)
     self.assertIn("Invalid string or not terminated: bar",
                   str(context.exception))
Beispiel #13
0
 def test_string_var(self):
     s = io.StringIO('''"""docstring""" \n ___foo___="bar"''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "docstring", 'foo': 'bar'})
Beispiel #14
0
 def test_error_invalid_docstring(self):
     s = io.StringIO('''"not a docstring"''')
     with self.assertRaises(ParseException) as context:
         read_metadata(s)
     self.assertIn("Docstring delimiter expected", str(context.exception))
Beispiel #15
0
 def test_invalid_list_with_missing_comma(self):
     s = io.StringIO('''"""docstring""" \n ___list___ = ["foo" "bar"]''')
     with self.assertRaises(ParseException) as context:
         output = read_metadata(s)
     self.assertIn("Expected comma, got '\"'", str(context.exception))
Beispiel #16
0
 def test_docstring_with_leading_whitespace(self):
     s = io.StringIO('''  \t"""foo\nbar"""  \t\r\n''')
     output = read_metadata(s)
     self.assertEqual(output, {'doc': "foo\nbar"})