Beispiel #1
0
 def parse_fail(self):
     input = """
     TEXT
         ***
            NOT VALID
     """
     self.assertRaises(load(input), AnsibleParserError)
Beispiel #2
0
 def parse_fail(self):
     input = """
     TEXT
         ***
            NOT VALID
     """
     self.assertRaises(load(input), AnsibleParserError)
Beispiel #3
0
    def load_data(self, ds):
        ''' walk the input datastructure and assign any values '''

        assert ds is not None

        if isinstance(ds, string_types) or isinstance(ds, FileIO):
            ds = load(ds)

        # we currently don't do anything with private attributes but may
        # later decide to filter them out of 'ds' here.

        ds = self.munge(ds)

        # walk all attributes in the class
        for (name, attribute) in iteritems(self._get_base_attributes()):

            # copy the value over unless a _load_field method is defined
            if name in ds:
                method = getattr(self, '_load_%s' % name, None)
                if method:
                    self._attributes[name] = method(name, ds[name])
                else:
                    self._attributes[name] = ds[name]

        # return the constructed object
        self.validate()
        return self
Beispiel #4
0
 def parse_yaml_from_dict(self):
     input = """
     asdf: '1234'
     jkl: 5678
     """
     output = load(input)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #5
0
 def parse_yaml_from_dict(self):
     input = """
     asdf: '1234'
     jkl: 5678
     """
     output = load(input)
     assert output['asdf'] == '1234'
     assert output['jkl'] == 5678
Beispiel #6
0
 def test_parse_yaml_from_dict(self):
     data = """
     asdf: '1234'
     jkl: 5678
     """
     output = load(data)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #7
0
 def parse_yaml_from_dict(self):
     input = """
     asdf: '1234'
     jkl: 5678
     """
     output = load(input)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #8
0
 def parse_json_from_string(self):
     input = """
     {
         "asdf" : "1234",
         "jkl" : 5678
     }
     """
     output = load(input)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #9
0
 def parse_json_from_string(self):
     input = """
     {
         "asdf" : "1234",
         "jkl" : 5678
     }
     """
     output = load(input)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #10
0
 def test_parse_json_from_string(self):
     data = """
     {
         "asdf" : "1234",
         "jkl" : 5678
     }
     """
     output = load(data)
     self.assertEqual(output['asdf'], '1234')
     self.assertEqual(output['jkl'], 5678)
Beispiel #11
0
 def parse_json_from_string(self):
     input = """
     {
         "asdf" : "1234",
         "jkl" : 5678
     }
     """
     output = load(input)
     assert output['asdf'] == '1234'
     assert output['jkl'] == 5678
Beispiel #12
0
 def parse_fail_from_file(self):
     self.assertRaises(load(MockFile(None, 'fail')), AnsibleParserError)
Beispiel #13
0
 def parse_json_from_file(self):
     output = load(MockFile(dict(a=1,b=2,c=3)),'json')
     self.assertEqual(ouput, dict(a=1,b=2,c=3))
Beispiel #14
0
 def parse_yaml_from_file(self):
     output = load(MockFile(dict(a=1, b=2, c=3), 'yaml'))
     self.assertEqual(output, dict(a=1, b=2, c=3))
Beispiel #15
0
 def parse_json_from_file(self):
     output = load(MockFile(dict(a=1, b=2, c=3)), 'json')
     self.assertEqual(ouput, dict(a=1, b=2, c=3))
Beispiel #16
0
 def parse_yaml_from_file(self):
     output = load(MockFile(dict(a=1, b=2, c=3), 'yaml'))
     assert output == dict(a=1, b=2, c=3)
Beispiel #17
0
 def parse_json_from_file(self):
     output = load(MockFile(dict(a=1, b=2, c=3)), 'json')
     assert ouput == dict(a=1, b=2, c=3)
Beispiel #18
0
 def parse_fail_from_file(self):
     self.assertRaises(load(MockFile(None,'fail')), AnsibleParserError)
Beispiel #19
0
 def parse_yaml_from_file(self):
     output = load(MockFile(dict(a=1,b=2,c=3),'yaml'))
     self.assertEqual(output, dict(a=1,b=2,c=3))