def tet_read_dict(self): cd = ConfigDict(TestConfigDict.existing_fh) assert cd['a'] == '5' assert cd['b'] == '10' assert cd['c'] == 'this=that' with pytest.raises(ConfigKeyError): print(cd['x'])
def test_write_dict(self): cd = ConfigDict(TestConfigDict.existing_fh) cd['zz'] = 'top' cd2 = ConfigDict(TestConfigDict.existing_fh) assert cd2['zz'] == 'top'
def test_bad_filepath(self): with pytest.raises(IOError): ConfigDict(TestConfigDict.bad_path)
def test_new_filename(self): assert not os.path.isfile(TestConfigDict.new_fh) cd = ConfigDict(TestConfigDict.new_fh) assert cd._config_file == TestConfigDict.new_fh assert os.path.isfile(cd._config_file)
def test_existing_filename(self): cd = ConfigDict(TestConfigDict.existing_fh) assert cd._config_file == TestConfigDict.existing_fh
def test_obj(self): cd = ConfigDict(TestConfigDict.existing_fh) assert isinstance(cd, ConfigDict) assert isinstance(cd, dict)
import sys from Assignment3 import ConfigDict cd = ConfigDict('config_file.txt') if len(sys.argv) == 3: key = sys.argv[1] value = sys.argv[2] print('writing data: {0}, {1}'.format(key, value)) cd[key] = value else: print('reading data') for key in cd.keys(): print(' {0} = {1}'.format(key, cd[key]))