示例#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)
示例#2
0
    def test_write_json(self):
        n = config_manager.Namespace(doc='top')
        n.add_option('aaa', '2011-05-04T15:10:00', 'the a',
          short_form='a',
          from_string_converter=dtu.datetime_from_ISO_string
        )

        def value_iter():
            yield 'aaa', 'aaa', n.aaa

        s = StringIO()
        ValueSource.write(value_iter, output_stream=s)
        received = s.getvalue()
        s.close()
        jrec = json.loads(received)

        expect_to_find = {
          "short_form": "a",
          "default": "2011-05-04T15:10:00",
          "doc": "the a",
          "value": "2011-05-04T15:10:00",
          "from_string_converter":
              "configman.datetime_util.datetime_from_ISO_string",
          "name": "aaa"
        }
        for key, value in expect_to_find.items():
            self.assertEqual(jrec['aaa'][key], value)
示例#3
0
    def test_write_json(self):
        n = config_manager.Namespace(doc='top')
        n.add_option('aaa',
                     '2011-05-04T15:10:00',
                     'the a',
                     short_form='a',
                     from_string_converter=dtu.datetime_from_ISO_string)

        def value_iter():
            yield 'aaa', 'aaa', n.aaa

        s = StringIO()
        ValueSource.write(value_iter, output_stream=s)
        received = s.getvalue()
        s.close()
        jrec = json.loads(received)

        expect_to_find = {
            "short_form": "a",
            "default": "2011-05-04T15:10:00",
            "doc": "the a",
            "value": "2011-05-04T15:10:00",
            "from_string_converter":
            "configman.datetime_util.datetime_from_ISO_string",
            "name": "aaa"
        }
        for key, value in expect_to_find.items():
            self.assertEqual(jrec['aaa'][key], value)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)