Some testing
This commit is contained in:
parent
8b334c532e
commit
ccd4e3232a
2
main.py
2
main.py
@ -4,12 +4,14 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import contentapi
|
import contentapi
|
||||||
import toml
|
import toml
|
||||||
|
import myutils
|
||||||
|
|
||||||
CONFIGFILE="config.toml"
|
CONFIGFILE="config.toml"
|
||||||
|
|
||||||
# The entire config object with all defaults
|
# The entire config object with all defaults
|
||||||
config = {
|
config = {
|
||||||
"api" : "https://oboy.smilebasicsource.com/api",
|
"api" : "https://oboy.smilebasicsource.com/api",
|
||||||
|
"expire_seconds" : 31536000, # 365 days in seconds, expiration for token
|
||||||
"tokenfile" : ".qcstoken"
|
"tokenfile" : ".qcstoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
myutils.py
Normal file
10
myutils.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Merge the "new_values" dictionary recursively into the "base_values" dictionary,
|
||||||
|
# assigning where new_values is assigned but not fully overwriting nested dictionaries
|
||||||
|
# (hence recursive)
|
||||||
|
def merge_dictionary(new_values, base_values):
|
||||||
|
for key in new_values:
|
||||||
|
if key in base_values and isinstance(base_values[key], dict) and isinstance(new_values[key], dict):
|
||||||
|
merge_dictionary(new_values[key], base_values[key])
|
||||||
|
else:
|
||||||
|
base_values[key] = new_values[key]
|
7
test.bat
Normal file
7
test.bat
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
REM Change python whatever
|
||||||
|
set pyexe=python34\python.exe
|
||||||
|
|
||||||
|
REM And now, run all the various tests we have
|
||||||
|
%pyexe% test_myutils.py
|
47
test_myutils.py
Normal file
47
test_myutils.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import unittest
|
||||||
|
import myutils
|
||||||
|
|
||||||
|
class TestMergeDictionary(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
# Test case 1: simple merge
|
||||||
|
base = {'a': 1, 'b': 2}
|
||||||
|
new = {'b': 3, 'c': 4}
|
||||||
|
expected = {'a': 1, 'b': 3, 'c': 4}
|
||||||
|
myutils.merge_dictionary(new, base)
|
||||||
|
self.assertDictEqual(base, expected)
|
||||||
|
|
||||||
|
def test_nested(self):
|
||||||
|
# Test case 2: nested dictionary merge
|
||||||
|
base = {'a': {'b': 1, 'c': 2}, 'd': 3}
|
||||||
|
new = {'a': {'b': 4, 'e': 5}, 'f': 6}
|
||||||
|
expected = {'a': {'b': 4, 'c': 2, 'e': 5}, 'd': 3, 'f': 6}
|
||||||
|
myutils.merge_dictionary(new, base)
|
||||||
|
self.assertDictEqual(base, expected)
|
||||||
|
|
||||||
|
def test_emptybase(self):
|
||||||
|
# Test case 3: empty base dictionary
|
||||||
|
base = {}
|
||||||
|
new = {'a': 1, 'b': {'c': 2}}
|
||||||
|
expected = {'a': 1, 'b': {'c': 2}}
|
||||||
|
myutils.merge_dictionary(new, base)
|
||||||
|
self.assertDictEqual(base, expected)
|
||||||
|
|
||||||
|
def test_emptynew(self):
|
||||||
|
# Test case 4: empty new dictionary
|
||||||
|
base = {'a': 1, 'b': {'c': 2}}
|
||||||
|
new = {}
|
||||||
|
expected = {'a': 1, 'b': {'c': 2}}
|
||||||
|
myutils.merge_dictionary(new, base)
|
||||||
|
self.assertDictEqual(base, expected)
|
||||||
|
|
||||||
|
def test_nooverlap(self):
|
||||||
|
# Test case 5: no overlapping keys
|
||||||
|
base = {'a': 1}
|
||||||
|
new = {'b': 2}
|
||||||
|
expected = {'a': 1, 'b': 2}
|
||||||
|
myutils.merge_dictionary(new, base)
|
||||||
|
self.assertDictEqual(base, expected)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user