示例#1
0
    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)
示例#2
0
class TestParser(TestPassing):

    _entry = cw.Parser({'key': 1.})

    def test_parser(self):

        p = cw.Parser(self._entry)
        self.assertEqual(self._entry.raw, p.raw)
示例#3
0
 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)
示例#4
0
    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))
示例#5
0
 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)
示例#6
0
    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)
示例#7
0
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)
示例#8
0
    def test_parser(self):

        with self.assertRaises(TypeError):
            cw.Parser(self._entry)
示例#9
0
    def test_update_parser(self):

        p = self._entry
        p.update(cw.Parser(self._new))
        self.check(p)
示例#10
0
    def test_update_dict(self):

        p = cw.Parser(self._dict)
        p.update(self._new)
        self.check(p)
示例#11
0
    def test_parser(self):

        p = cw.Parser(self._entry)
        self.assertEqual(self._entry.raw, p.raw)