Exemple #1
0
 def test_get_values(self):
     j = {'a': '1', 'b': 2, 'c': {'d': 'x', 'e': 'y'}, 'd': {'d': 'X'}}
     tmp_filename = os.path.join(tempfile.gettempdir(), 'test.json')
     with open(tmp_filename, 'w') as f:
         json.dump(j, f)
     try:
         jvs = ValueSource(tmp_filename)
         vals = jvs.get_values(None, True, DotDict)
         self.assertTrue(isinstance(vals, DotDict))
         vals = jvs.get_values(None, True, DotDictWithAcquisition)
         self.assertTrue(isinstance(vals, DotDictWithAcquisition))
         self.assertEqual(vals.d.b, 2)
     finally:
         if os.path.isfile(tmp_filename):
             os.remove(tmp_filename)
Exemple #2
0
 def test_for_json_basics(self):
     tmp_filename = os.path.join(tempfile.gettempdir(), 'test.json')
     j = {'fred': 'wilma',
          'number': 23,
         }
     with open(tmp_filename, 'w') as f:
         json.dump(j, f)
     try:
         jvs = ValueSource(tmp_filename)
         vals = jvs.get_values(None, True)
         self.assertEqual(vals['fred'], 'wilma')
         self.assertEqual(vals['number'], 23)
     finally:
         if os.path.isfile(tmp_filename):
             os.remove(tmp_filename)