def test_read_dict(self): cc = MyCustomDict(TestMyCustomDict.existing_file) assert cc['a'] == '5' assert cc['b'] == '10' assert cc['c'] == 'this=that' with pytest.raises(MyDictError): print cc['x']
def test_write_dict(self): c = MyCustomDict(TestMyCustomDict.existing_file) c['z'] = 'hello' c2 = MyCustomDict(TestMyCustomDict.existing_file) assert c2['z']
def test_bad_file_path(self): with pytest.raises(IOError): MyCustomDict(TestMyCustomDict.bad_path)
def test_new_filename(self): assert not os.path.isfile(TestMyCustomDict.new_file) c = MyCustomDict(TestMyCustomDict.new_file) assert c._filename == TestMyCustomDict.new_file assert os.path.isfile(TestMyCustomDict.new_file)
def test_existing_filename(self): c = MyCustomDict(TestMyCustomDict.existing_file) assert c._filename == TestMyCustomDict.existing_file
def test_obj(self): c = MyCustomDict(TestMyCustomDict.existing_file) assert isinstance(c, MyCustomDict) assert isinstance(c, dict)
#!/usr/bin/python __author__ = 'Mayank' """ Usages : ./testAss4.py (display entire dict) ./testAss4.py <key> (print's the value associated with the key) ./testAss4.py <key> <value> (sets given key and value in the dict) """ import sys from assignment4 import MyCustomDict d = MyCustomDict('rev_analysis.txt') if len(sys.argv) == 3: key = sys.argv[1] value = sys.argv[2] print('setting key "{0}" and value "{1}" in dictionary'.format(key, value)) d[key] = value elif len(sys.argv) == 2: print('reading a value from dictionary') key = sys.argv[1] print('the value for key "{0}" is : "{1}"'.format(key, d[key])) else: print("Displaying dictionary : ") for key in d.keys(): print("{0} = {1}".format(key, d[key]))