-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_common.py
75 lines (53 loc) · 1.77 KB
/
test_common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
from unittest import TestCase
from touchstone import common
class TestCommon(TestCase):
def test_dictMerge_emptyOverride_ReturnsBase(self):
# Given
base = {'foo': 'bar'}
override = {}
# When
result = common.dict_merge(base, override)
# Then
self.assertDictEqual(result, base)
def test_dictMerge_noOverlap_ReturnsCombined(self):
# Given
base = {'foo': 'bar'}
override = {'bar': 'foo'}
# When
result = common.dict_merge(base, override)
# Then
expected = {'foo': 'bar', 'bar': 'foo'}
self.assertDictEqual(result, expected)
def test_dictMerge_withOverlap_OverrideTakesPrecedence(self):
# Given
base = {'foo': 'bar', 'bar': 'foo'}
override = {'bar': 'buzz'}
# When
result = common.dict_merge(base, override)
# Then
expoected = {'foo': 'bar', 'bar': 'buzz'}
self.assertDictEqual(result, expoected)
def test_toSnake_string_ReturnsSnake(self):
# Given
input = 'fooBar'
# When
result = common.to_snake(input)
# Then
self.assertEqual(result, 'foo_bar')
def test_toSnake_dict_ReturnsSnakeKeys(self):
# Given
input = {'fooKey': 'barValue'}
# When
result = common.to_snake(input)
# Then
self.assertDictEqual(result, {'foo_key': 'barValue'})
def test_toSnake_listOfDicts_ReturnsSnakeKeys(self):
# Given
input = [{'fooKey': 'barValue'}, {'barKey': 'fooValue'}]
# When
result = common.to_snake(input)
# Then
self.assertListEqual(result, [{'foo_key': 'barValue'}, {'bar_key': 'fooValue'}])
if __name__ == '__main__':
unittest.main()