def test_load_obj(self): test_data = { 'metadata': { 'foo': 'bar' }, 'name': ['Johnny', 'B', 'Good'], 'class': { 'module': 'fractions', 'name': 'Fraction' }, 'data': {} } after = BW2Package._load_obj(copy.deepcopy(test_data), False) for key in test_data: self.assertTrue(key in after) with self.assertRaises(InvalidPackage): BW2Package._load_obj({}) self.assertEqual(after['class'], fractions.Fraction)
def test_load_obj(self): test_data = { "metadata": { "foo": "bar" }, "name": ["Johnny", "B", "Good"], "class": { "module": "fractions", "name": "Fraction" }, "data": {}, } after = BW2Package._load_obj(copy.deepcopy(test_data), False) for key in test_data: self.assertTrue(key in after) with self.assertRaises(InvalidPackage): BW2Package._load_obj({}) self.assertEqual(after["class"], fractions.Fraction)
def test_create_obj(self): mock_data = { 'class': { 'module': 'bw2io.tests', 'name': 'MockDS' }, 'metadata': { 'circle': 'square' }, 'data': [], 'name': 'Wilhelm' } data = BW2Package._load_obj(mock_data) obj = BW2Package._create_obj(data) self.assertTrue(isinstance(obj, MockDS)) self.assertTrue("Wilhelm" in mocks) self.assertEqual(mocks['Wilhelm'], {'circle': 'square'}) mocks.__init__() self.assertEqual(mocks['Wilhelm'], {'circle': 'square'}) self.assertEqual(MockDS("Wilhelm").load(), [])
def test_create_obj(self): mock_data = { "class": { "module": "bw2io.tests", "name": "MockDS" }, "metadata": { "circle": "square" }, "data": [], "name": "Wilhelm", } data = BW2Package._load_obj(mock_data) obj = BW2Package._create_obj(data) self.assertTrue(isinstance(obj, MockDS)) self.assertTrue("Wilhelm" in mocks) self.assertEqual(mocks["Wilhelm"], {"circle": "square"}) mocks.__init__() self.assertEqual(mocks["Wilhelm"], {"circle": "square"}) self.assertEqual(MockDS("Wilhelm").load(), [])