def test_resources(self): source = """# Resources test file # Another comment :res1 # comment one: 1 two: 2 two: II :Foo.Bar one: eleven """ fl = io.StringIO(source) ress = Resources('<unit test>', fl) fl.close() self.assertTrue(ress.get('foo') is None) res = ress.get('res1') self.assertTrue(res in ress.resources()) self.assertEqual(res.get_one('one'), '1') self.assertEqual(res.get_one('two'), '2') self.assertEqual(res.get_all('two'), ['2', 'II']) self.assertEqual(res.get_one('missing'), None) self.assertEqual(res.get_one('missing', 'def'), 'def') res = ress.get('Foo.Bar') self.assertTrue(res in ress.resources()) self.assertEqual(res.get_one('one'), 'eleven') self.assertEqual(res.get_one('two'), None) keys = list(ress.keys()) self.assertEqual(len(keys), 2) self.assertTrue('res1' in keys and 'Foo.Bar' in keys)
def test_resources_empty(self): ress = Resources('<test>') self.assertEqual(len(ress), 0) self.assertTrue(ress.get('foo') is None) self.assertEqual(list(ress.keys()), []) self.assertEqual(ress.resources(), [])