Exemple #1
0
    def test_metadata(self):
        source = """# Metadata test file

one: 1
two: 2
dc.three: 3
one: 11

four : Four
"""
        fl = io.StringIO(source)
        meta = Metadata('<unit test>', fl)
        fl.close()

        self.assertEqual(meta.get_one('one'), '1')
        self.assertEqual(meta.get_one('dc.three'), '3')
        self.assertEqual(meta.get_one('four'), 'Four')
        self.assertEqual(meta.get_one('four', 'def'), 'Four')
        self.assertEqual(meta.get_one('missing'), None)
        self.assertEqual(meta.get_one('missing', 'def'), 'def')

        self.assertEqual(meta.get_all('two'), ['2'])
        self.assertEqual(meta.get_all('one'), ['1', '11'])
        self.assertEqual(meta.get_all('missing'), [])

        ls = list(meta.keys())
        self.assertEqual(len(ls), len(meta))
        ls.sort()
        self.assertEqual(ls, ['dc.three', 'four', 'one', 'two'])

        meta2 = meta.clone()
        self.assertEqual(len(meta2), len(meta))
        for key in list(meta.keys()):
            self.assertEqual(meta.get_all(key), meta2.get_all(key))
Exemple #2
0
    def test_metadata_modify(self):
        meta = Metadata('<test>')
        meta.add('one', 'two')

        meta2 = meta.clone()
        meta2.add('one', 'four')
        self.assertEqual(meta2.get_all('one'), ['two', 'four'])

        meta.add('one', 'three')
        self.assertEqual(meta.get_all('one'), ['two', 'three'])
        self.assertEqual(meta2.get_all('one'), ['two', 'four'])

        meta.delete_all('one')
        meta.delete_all('nonexistent')
        self.assertEqual(meta.get_all('one'), [])
        self.assertEqual(meta2.get_all('one'), ['two', 'four'])