Пример #1
0
 def test_get_first(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     self.assertEqual(linked.get('/string', strategy=FindStrategy.FIRST), 'other')
     self.assertEqual(linked.get('/list/0', strategy=FindStrategy.FIRST), 'some')
     self.assertEqual(linked.get('/nonexistent'), None)
Пример #2
0
 def test_get_collect(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     self.assertEqual(linked.get('/string', strategy=FindStrategy.COLLECT),
                      ['other', 'value'])
     self.assertEqual(linked.get('/list', strategy=FindStrategy.COLLECT),
                      [['some', 'more'], ['string', 1, None, True]])
     self.assertEqual(linked.get('/dict', strategy=FindStrategy.COLLECT),
                      [{'x': 'X', 'y': 'Y'}, {'a': 'A', 'b': 'B'}])
     self.assertEqual(linked.get('/sometimes', strategy=FindStrategy.COLLECT), [['here']])
Пример #3
0
 def test_get_merge(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     self.assertEqual(linked.get('/list', strategy=FindStrategy.MERGE),
                      ['string', 1, None, True, 'some', 'more'])
     self.assertEqual(linked.get('/dict', strategy=FindStrategy.MERGE),
                      {'a': 'A', 'b': 'B', 'x': 'X', 'y': 'Y'})
     self.assertEqual(linked.get('/sometimes', strategy=FindStrategy.MERGE), ['here'])
     with self.assertRaises(MergeError):
         linked.get('/string', strategy=FindStrategy.MERGE)
Пример #4
0
 def test_default_merge(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     sentinel = object()
     self.assertIs(linked.get('/nonexistent', sentinel, strategy=FindStrategy.MERGE),
                   sentinel)
Пример #5
0
 def test_default(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     sentinel = object()
     self.assertIs(linked.get('/nonexistent', sentinel), sentinel)
Пример #6
0
 def test_delete(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     linked.delete('/list')
     self.assertIsNone(linked.get('/list'))
Пример #7
0
 def test_set(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     linked.set('/new', 'foo')
     self.assertEqual(linked.get('/new'), 'foo')