Пример #1
0
    def test_can_wrap_multiple_outputs_with_mapping(self):
        m = mock.Mock(return_value=(210, 220))
        s = DataSourceWrapper(fields=[('field3', 'remote3'), 'field1'], source=m)

        assert s.fields == ['field3', 'field1']

        with s:
            d = s.read()
        assert d == {'field3': 210, 'field1': 220}
Пример #2
0
    def test_can_wrap_single_output_with_mapping(self):
        m = mock.Mock(return_value=(110, 120))
        s = DataSourceWrapper(fields=[('field3', 'remote3')], source=m)

        assert s.fields == ['field3']

        with s:
            d = s.read()
        assert d == {'field3': (110, 120)}
Пример #3
0
    def test_can_wrap_object_properties(self):
        class O:
            def __init__(self):
                self._count = 0

            @property
            def value(self):
                self._count += 1
                return self._count

        obj = O()
        s = DataSourceWrapper(source=obj, fields=[('result', 'value')])

        with s:
            d = s.read()
            assert d == {'result': 1}

            d = s.read()
            assert d == {'result': 2}