Пример #1
0
 def test_simple(self):
     root = mock.Mock()
     result = data.parse_pointer('test::something')
     self.assertEquals(str(result), '<test::something>')
     result(root)
     root.getentry.assert_called_once_with(['test', 'something'])
     modifiers = result.modifiers()
     self.assertFalse(list(modifiers), list())
Пример #2
0
 def test_reference(self):
     root = mock.Mock()
     root.get = mock.Mock(return_value='outer')
     root.getentry = mock.Mock(return_value='result')
     result = data.parse_pointer('test::<test::inner>')
     self.assertEquals(str(result), '<test::<test::inner>>')
     self.assertEquals(result(root), 'result')
     root.get.assert_called_once_with(['test', 'inner'])
     root.getentry.assert_called_once_with(['test', 'outer'])
     modifiers = result.modifiers()
     self.assertIn(['test', 'inner'], modifiers)
Пример #3
0
    def test_double_reference(self):
        def entry_get(key):
            return 'two' if key == ['test', 'three'] else 'one'

        root = mock.Mock()
        root.get = mock.Mock(wraps=entry_get)
        root.getentry = mock.Mock(return_value='zero')
        result = data.parse_pointer('test::<test::<test::three>>')
        self.assertEquals(str(result), '<test::<test::<test::three>>>')
        self.assertEquals(result(root), 'zero')
        root.get.assert_any_call(['test', 'three'])
        root.get.assert_called_with(['test', 'two'])
        root.getentry.assert_called_with(['test', 'one'])
        self.assertEquals(root.get.call_count, 2)
        modifiers = result.modifiers()
        self.assertIn(['test', 'three'], modifiers)