Beispiel #1
0
    def test_eq(self):
        delve1 = JsonDelver(self.file1.name)
        delve2 = JsonDelver(self.file2.name)
        delve3 = DataDelver(delve1.get('').copy())
        linked = ChainedDelver(delve1, delve2)
        notequal = ChainedDelver(delve2, delve1)
        equal = ChainedDelver(delve3, delve2)

        self.assertNotEqual(linked, notequal)
        self.assertEqual(linked, equal)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
0
 def test_cd(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     subset = linked.cd('/dict')
     self.assertEqual(subset.get('/a'), 'A')
     self.assertEqual(subset.get('/x'), 'X')
Beispiel #5
0
 def test_symlink(self):
     link = Path('/tmp/symlink')
     try:
         link.symlink_to(self.file1.name)
         delve1 = JsonDelver(self.file1.name)
         delve2 = JsonDelver(link)
         with self.assertRaises(DuplicateInChainError):
             ChainedDelver(delve1, delve2)
     finally:
         link.unlink()
Beispiel #6
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']])
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
 def test_delete_nonexistent(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name)
     linked = ChainedDelver(delve1, delve2)
     linked.delete('/nonexistent')
Beispiel #10
0
 def test_delete_readonly(self):
     delve1 = JsonDelver(self.file1.name)
     delve2 = JsonDelver(self.file2.name, readonly=True)
     linked = ChainedDelver(delve1, delve2)
     with self.assertRaises(ReadonlyError):
         linked.delete('/list')
Beispiel #11
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'))
Beispiel #12
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')