Ejemplo n.º 1
0
    def test_new_file(self):
        if os.path.isfile('config_file.txt'):
            os.system('rm config_file.txt')

        dict1 = ConfigDict('config_file.txt')
        assert os.path.isfile('config_file.txt')
        os.system('rm config_file.txt')
Ejemplo n.º 2
0
import sys
from assignment4 import ConfigDict

cd = ConfigDict('revanalysis.config')

if len(sys.argv) == 3:
    key = sys.argv[1]
    value = sys.argv[2]
    print('writing data: {}, {}'.format(key, value))
    cd[key] = value

elif len(sys.argv) == 2:
    print('reading a value')
    key = sys.argv[1]
    print('the value for {} is {}'.format(sys.argv[1], cd[key]))

else:
    print('keys/values:')
    for key in cd.keys():
        print('    {} = {}'.format(key, cd[key]))
Ejemplo n.º 3
0
#!/usr/bin/python
"""
    Usages:
    ./test.py                    (reads out the entire config dict)
    ./test.py thatkey            (prints the value associated with this key)
    ./test.py thiskey thisvalue  (sets 'thiskey' and 'thisvalue' in the dict)
"""
import sys
from assignment4 import ConfigDict  # assumes "assignment4.py" holds a
# class called ConfigDict

cd = ConfigDict('config.txt')

# if 2 arguments on the command line,
# set a key and value in the object's dictionary
if len(sys.argv) == 3:
    key = sys.argv[1]
    value = sys.argv[2]
    print('writing data:  {0}, {1}'.format(key, value))
    cd[key] = value

# if 1 argument on the command line, treat it as a key and show the value
elif len(sys.argv) == 2:
    print('reading a value')
    key = sys.argv[1]
    print('the value for {0} is {1}'.format(sys.argv[1], cd[key]))

# if no arguments on the command line, show all keys and values
else:
    print('keys/values:')
    for key in cd.keys():
Ejemplo n.º 4
0
 def test_bad_path(self):
     with pytest.raises(IOError):
         ConfigDict('badpath/config_file.txt')
Ejemplo n.º 5
0
    def example(self):
        configdict = ConfigDict('config_file.txt')

        return configdict
# Python v3.5.1

'''
	Usages:

		./test.py 											(reads out the entire config dict)
		./test.py thatkey								(prints the value assosiated with this key)
		./test.py thiskey thisvalue 		(sets 'thiskey' and 'thisvalue' in the dict)

'''

import sys
from assignment4 import ConfigDict

cd = ConfigDict('revanalysis.config')

# if 2 arguments on the command line, set a key and value in the objects dictionary
if len(sys.argv) == 3:
	key = sys.argv[1]
	value = sys.argv[2]
	print('writing data: {0}, {1}'.format(key, value))
	cd[key] = value

# if 1 argument on the command line, treat it as a key and show the value
elif len(sys.argv) == 2:
	print('reading a value')
	key = sys.argv[1]
	print('the value for {0} is {1}'.format(sys.argv[1], cd[key]))

# if no arguments on the command line, show all keys and values
else: