def test_init_from_str(self): a = InputFileLoaderCheckerSaver() a._attributes = "a b".split() a._initialize_attributes() a.__init__('a=4\nb=6') assert_equal(a.a, 4) assert_equal(a.b, 6) assert_equal(a._input_text, 'a=4\nb=6')
def test_init_from_fileobj(self): a = InputFileLoaderCheckerSaver() a._attributes = "a b".split() a._initialize_attributes() with open(os.path.join(self.tempdir.path, 'inp1.py'), 'r') as f: a.__init__(f) assert_equal(a.a, 4) assert_equal(a.b, 6) assert_equal(a._input_text, 'a=4\nb=6')
def test_attribute_defaults(self): a = InputFileLoaderCheckerSaver() a._input_text = 'b=6' a._attributes = "a b".split() a._attribute_defaults = {'a': 24} a._initialize_attributes() a._transfer_attributes_from_inputfile() assert_equal(a.a, 24) assert_equal(a.b, 6) assert_equal(a._input_text, 'b=6')
def test_save_data_parsed(self): a = InputFileLoaderCheckerSaver() a._attributes = "a b ".split() a.save_data_to_file=True # a._initialize_attributes() a.a=4 a.b=6 a._save_data() # print(os.listdir(self.tempdir.path)) # print(os.listdir(os.path.join(self.tempdir.path,'out0002'))) assert_equal(self.tempdir.read( ('out0002','out0002_input_parsed.py'), 'utf-8').strip().splitlines(), 'a = 4\nb = 6'.splitlines())