Ejemplo n.º 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'])
Ejemplo n.º 2
0
"""
 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'
Ejemplo n.º 3
0
 def test_write_dict(self):
     cd = ConfigDict(TestConfigDict.existing_fh)
     cd['zz'] = 'top'
     cd2 = ConfigDict(TestConfigDict.existing_fh)
     assert cd2['zz'] == 'top'
Ejemplo n.º 4
0
 def test_bad_filepath(self):
     with pytest.raises(IOError):
         ConfigDict(TestConfigDict.bad_path)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def test_existing_filename(self):
     cd = ConfigDict(TestConfigDict.existing_fh)
     assert cd._config_file == TestConfigDict.existing_fh
Ejemplo n.º 7
0
 def test_obj(self):
     cd = ConfigDict(TestConfigDict.existing_fh)
     assert isinstance(cd, ConfigDict)
     assert isinstance(cd, dict)