示例#1
0
    def test_is_modified(self):
        json_dict = self.parser.get_sections()

        p = InputParser(json_dict)
        p.parse()
        p.set_section_property('optimizer', 'maxfun', 1002)
        self.assertTrue(p.is_modified())
        self.assertEqual(p.get_section_property('optimizer', 'maxfun'), 1002)
示例#2
0
    def test_load_from_dict(self):
        json_dict = self.parser.get_sections()

        p = InputParser(json_dict)
        p.parse()
        dict1 = json.loads(json.dumps(self.parser.get_sections()))
        dict2 = json.loads(json.dumps(p.get_sections()))
        self.assertEqual(dict1, dict2)
示例#3
0
    def test_save(self):
        save_path = self._get_resource_path('output.txt')
        self.parser.save_to_file(save_path)

        p = InputParser(save_path)
        p.parse()
        os.remove(save_path)
        dict1 = json.loads(json.dumps(self.parser.get_sections()))
        dict2 = json.loads(json.dumps(p.get_sections()))
        self.assertEqual(dict1, dict2)
示例#4
0
    def test_validate(self):
        json_dict = self.parser.get_sections()

        p = InputParser(json_dict)
        p.parse()
        try:
            p.validate_merge_defaults()
        except Exception as e:
            self.fail(str(e))

        p.set_section_property('optimizer', 'dummy', 1002)
        self.assertRaises(AlgorithmError, p.validate_merge_defaults)
示例#5
0
 def load_file(self,filename):
     if filename is None:
         return []
     try:
         self._parser = InputParser(filename)
         self._parser.parse()
         uipreferences = UIPreferences()
         if uipreferences.get_populate_defaults(True):
             self._parser.validate_merge_defaults()
             self._parser.commit_changes()
             
         return self._parser.get_section_names()   
     except:
         self._parser = None
         raise
示例#6
0
 def new(self):
     try:
         dict = {}
         jsonfile = os.path.join(os.path.dirname(__file__), 'input_template.json')
         with open(jsonfile) as json_file:
             dict = json.load(json_file)
             
         self._parser = InputParser(dict)
         self._parser.parse()
         uipreferences = UIPreferences()
         if uipreferences.get_populate_defaults(True):
             self._parser.validate_merge_defaults()
             self._parser.commit_changes()
             
         return self._parser.get_section_names()   
     except:
         self._parser = None
         raise
示例#7
0
 def __init__(self):
     """Create Model object."""
     self._parser = InputParser()
示例#8
0
 def setUp(self):
     filepath = self._get_resource_path('H2-0.735.json')
     self.parser = InputParser(filepath)
     self.parser.parse()