Пример #1
0
    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'])
Пример #2
0
 def test_write_dict(self):
     cd = ConfigDict(TestConfigDict.existing_fh)
     cd['zz'] = 'top'
     cd2 = ConfigDict(TestConfigDict.existing_fh)
     assert cd2['zz'] == 'top'
Пример #3
0
 def test_bad_filepath(self):
     with pytest.raises(IOError):
         ConfigDict(TestConfigDict.bad_path)
Пример #4
0
 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)
Пример #5
0
 def test_existing_filename(self):
     cd = ConfigDict(TestConfigDict.existing_fh)
     assert cd._config_file == TestConfigDict.existing_fh
Пример #6
0
 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]))