Exemplo n.º 1
0
def mapper(tmpdir, obj, attrs, request):
    path = request.param + "/path/to/file"
    backup = yorm.settings.fake
    if "fake" in path:
        yorm.settings.fake = True
    elif "real" in path:
        tmpdir.chdir()
    yield Mapper(obj, path, attrs, auto_track=False)
    yorm.settings.fake = backup
Exemplo n.º 2
0
    def test_missing_attributes_added(self):
        obj = self.MyObject()
        path = "mock/path"
        attrs = {'bar': Integer, 'qux': Integer}
        mapper = Mapper(obj, path, attrs)
        mapper.create()
        mapper.fetch()

        assert 1 == obj.foo
        assert 0 == obj.bar
        assert 0 == obj.qux
Exemplo n.º 3
0
    def test_auto_off(self, tmpdir):
        """Verify storage is delayed with auto off."""
        tmpdir.chdir()
        obj = self.MyObject()
        attrs = {'number': Integer}
        mapper = Mapper(obj, "real/path/to/file", attrs, auto=False)
        assert False is mapper.auto

        mapper.create()
        assert "" == mapper.text
        assert False is mapper.auto

        mapper.store()
        assert "" == mapper.text
        assert False is mapper.auto

        mapper.store(force=True)
        assert "number: 0\n" == mapper.text
        assert False is mapper.auto
Exemplo n.º 4
0
def mapper_fake(obj, attrs):
    backup = yorm.settings.fake
    yorm.settings.fake = True
    yield Mapper(obj, "fake/path/to/file", attrs)
    yorm.settings.fake = backup
Exemplo n.º 5
0
def mapper_real(tmpdir, obj, attrs):
    tmpdir.chdir()
    return Mapper(obj, "real/path/to/file", attrs)