def test_ignition(self): with open(EXAMPLES / 'ignition.yaml') as stream: yml = yaml.load(stream, Loader=yaml.SafeLoader) initial = cw.Parser(yml['defaults']['initial']) self.assertIsInstance(initial.T, pq.Quantity) self.assertIsInstance(initial['fuel'], str)
class TestParser(TestPassing): _entry = cw.Parser({'key': 1.}) def test_parser(self): p = cw.Parser(self._entry) self.assertEqual(self._entry.raw, p.raw)
def test_simulation(self): self.assertIsNone(self.sim.data) defaults = self.config['defaults'] if self._parser: self.sim.run(cw.Parser(defaults)) else: self.sim.run(defaults) self.assertEqual(type(self.sim.data).__name__, self._data_default)
def test_parser(self): p = cw.Parser(self._entry) self.assertEqual(self._entry, p.raw) for k, v in p.items(): orig = self._entry[k] if isinstance(v, cw.Parser): self.assertEqual(orig, v.raw) self.assertEqual(orig, p.get(k).raw) else: self.assertEqual(orig, v) self.assertEqual(orig, p.get(k))
def test_restart(self): defaults = self.config['defaults'] if self._parser: self.sim.run(cw.Parser(defaults)) else: self.sim.run(defaults) self.sim.run() old = self.sim.data if self.sim.has_restart: self.sim.restart(old) new = self.sim.data self.assertEqual(type(old), type(new)) #self.assertNotEqual(old, new) else: with self.assertRaisesRegex(NotImplementedError, "does not define 'restart'"): self.sim.restart(old)
def test000_parser(self): try: defaults = cw.fileio.load_yaml('ignition.yaml', path=path, keys=['defaults']) p = cw.Parser(defaults[0]['initial']) a = p.T # attribute b = p['T'] # get item c = p.T.m # magnitude e = p.T.to('degC') # unit conversion d = p.T.m_as('degC') # magnitude after unit conversion success = True except: success = False self.assertTrue(success)
class TestMulti(TestParser): _dict = {'foo': {'spam': 2.0, 'eggs': 3.14}, 'bar': 3, 'baz': '1. kelvin'} _entry = cw.Parser(_dict) _new = {'foo': {'eggs': 4}, 'bar': 5} def check(self, p): self.assertEqual(p.foo.spam, self._entry.foo.spam) self.assertEqual(p.baz, self._entry.baz) self.assertEqual(p.foo.eggs, self._new['foo']['eggs']) self.assertEqual(p.bar, self._new['bar']) def test_update_dict(self): p = cw.Parser(self._dict) p.update(self._new) self.check(p) def test_update_parser(self): p = self._entry p.update(cw.Parser(self._new)) self.check(p)
def test_parser(self): with self.assertRaises(TypeError): cw.Parser(self._entry)
def test_update_parser(self): p = self._entry p.update(cw.Parser(self._new)) self.check(p)
def test_update_dict(self): p = cw.Parser(self._dict) p.update(self._new) self.check(p)
def test_parser(self): p = cw.Parser(self._entry) self.assertEqual(self._entry.raw, p.raw)