Beispiel #1
0
 def test_get_method_key_not_exist(self):
     with pytest.raises(Exception):
         WritePickleDictToFile(test_dict_file)._file_content['d']
Beispiel #2
0
 def test_file_maneger(self):
     test_write_to_file = WritePickleDictToFile(file_name)
     test_write_to_file['a'] = 'yyy'
     test_read_file = WritePickleDictToFile(file_name)
     assert test_read_file._file_content == {
         'a': 'yyy'}, 'writing to file and reading comparing did not work.'
Beispiel #3
0
 def test_get_method(self):
     assert WritePickleDictToFile(
         test_dict_file)._file_content['a'] == 'yyy', 'get method is failing.'
Beispiel #4
0
 def test_read_dict(self):
     assert WritePickleDictToFile(test_dict_file)._file_content == {
         'a': 'yyy', 'b': 'ttt', 'c': 'uuu'}, 'reading file did not work right'
Beispiel #5
0
 def test_bad_file_path(self):
     with pytest.raises(FileNotFoundError):
         WritePickleDictToFile(bad_file_path), 'file path does not work.'
Beispiel #6
0
 def test_exiting_filename(self):
     pickle_dict = WritePickleDictToFile(file_name)
     assert os.path.isfile(file_name), 'file does not exist.'
Beispiel #7
0
 def test_object(self):
     pickle_dict = WritePickleDictToFile(file_name)
     assert isinstance(
         pickle_dict, WritePickleDictToFile), 'did not succeed to create an instense of WritePickleDictToFile.'
     assert isinstance(pickle_dict._file_content,
                       dict), 'did not succeed to create a dict instense.'
Beispiel #8
0
#!/usr/bin/python
"""
    Usages: 
    ./test.py            (reads out the entire config dict)
    ./test.py wheel      (gets the value for that key)
    ./test.py wheel air  (sets wheel as key and air as value in the dict)
"""
import sys
import os
from assignment5 import WritePickleDictToFile

file_name = './dict_file_1.txt'
dict_file = WritePickleDictToFile(file_name)

if len(sys.argv) == 3:
    key = sys.argv[1]
    value = sys.argv[2]
    dict_file[key] = value
    print('wrote "{0} = {1}" to a dict file.'.format(key, value))
elif len(sys.argv) == 2:
    print(str(sys.argv[1]) + ' = ' + str(dict_file[sys.argv[1]]))
else:
    empty_file = True
    print('Reading file: ')
    print('        key   value')
    for key, val in dict_file._file_content.items():
        empty_file = False
        print('          {0} : {1}'.format(key, val))
    if empty_file:
        print(' file is empty')