Ejemplo n.º 1
0
    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']
Ejemplo n.º 2
0
 def test_write_dict(self):
     c = MyCustomDict(TestMyCustomDict.existing_file)
     c['z'] = 'hello'
     c2 = MyCustomDict(TestMyCustomDict.existing_file)
     assert c2['z']
Ejemplo n.º 3
0
 def test_bad_file_path(self):
     with pytest.raises(IOError):
         MyCustomDict(TestMyCustomDict.bad_path)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def test_existing_filename(self):
     c = MyCustomDict(TestMyCustomDict.existing_file)
     assert c._filename == TestMyCustomDict.existing_file
Ejemplo n.º 6
0
 def test_obj(self):
     c = MyCustomDict(TestMyCustomDict.existing_file)
     assert isinstance(c, MyCustomDict)
     assert isinstance(c, dict)
Ejemplo n.º 7
0
#!/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]))
Ejemplo n.º 8
0
#!/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]))