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'])
""" Usages: ./run_assignment3.py (reads out hte entire config dict) ./run_assignment3.py thiskey this value (sets 'thiskey' and 'thisvalue' in the dict) """ import sys from assignments.assignment3 import ConfigDict cd = ConfigDict('config_file.txt') if len(sys.argv) == 3: key = sys.argv[1] value = sys.argv[2] print('writing data {key} {value}'.format(key=key, value=value)) else: print('reading data') for key in cd.keys(): print(' {key} = {value}'.format(key=key, value=cd[key])) cd['secret_password'] = '******' cd['username'] = '******' cd['password'] = '******' cd['hosntame'] = 'localhost' cd['port'] = 'port'
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)