def test_parse_inline_table_versioned_dependency(self):
        dep = parse_dependency('django',
                               InlineTable([('version', '==1.10.2')]))

        self.assertTrue(isinstance(dep, VersionedDependency))
        self.assertTrue(dep.pkg_name, 'django')
        self.assertEqual(dep.matcher.specifiers, '==1.10.2')
Beispiel #2
0
def _format_inline_table(tbl: InlineTable) -> str:
    res = []
    for key, val in tbl.items():
        if isinstance(val, InlineTable):
            raise NotSupported('Nested inline tables.')

        res.append(format_kv_entry(key, val))

    return '{' + ', '.join(res) + '}'
    def test_parse_various_values(self):
        text = """
[table]
one = 1
two = 2.2
three = [1, 2]
four = {one = 1, 1 = 3}
        """
        self.assertParsedCorrectly(
            text,
            Root(
                nodes={
                    'table':
                    Table(
                        nodes={
                            'one': 1,
                            'two': 2.2,
                            'three': [1, 2],
                            'four': InlineTable([('one', 1), ('1', 3)])
                        })
                }))
 def test_fail_if_invalid_marker(self):
     with self.assertRaises(InvalidEnvironmentMarkers):
         dep = parse_dependency(
             'django',
             InlineTable([('version', '==1.10.2'),
                          ('markers', 'python_version1 >= "1.0"')]))
 def test_parse_dep_with_markers(self):
     dep = parse_dependency(
         'django',
         InlineTable([('version', '==1.10.2'),
                      ('markers', 'python_version >= "1.0"')]))
     self.assertEqual(dep.markers, 'python_version >= "1.0"')
Beispiel #6
0
 def test_parse_inline_table_preserves_order(self):
     self.assertValueParsedCorrectly('{one = 1, two = 2, three = 3}',
                                     InlineTable([('one', 1), ('two', 2), ('three', 3)]))
Beispiel #7
0
 def test_simple_entry(self):
     self.assertValueParsedCorrectly('{hello = "world"}', InlineTable(**{'hello': 'world'}))
Beispiel #8
0
 def test_empty_table(self):
     self.assertValueParsedCorrectly('{}', InlineTable())
Beispiel #9
0
 def test_inline_table(self):
     self.assertFormatted(InlineTable([('a', 1), ('b', 2)]),
                          '{a = 1, b = 2}')
Beispiel #10
0
 def for_toml(self):
     content = OrderedDict()
     content[self.protocol] = self.url
     content['editable'] = self.editable
     return InlineTable(content)