예제 #1
0
def test_loaders_version_test_missing():
    # pylint: disable=unused-variable
    test_registry = charon.CodecRegistry()

    @test_registry.loader(DummyClass, version=1)
    def _load_dummy_class_v1(_):
        pass

    charon.testing.ast_hash.test_loaders_version(charon.Codec([test_registry]))
예제 #2
0
def test_loaders_version_test_valid():
    # pylint: disable=unused-variable
    test_registry = charon.CodecRegistry()

    @test_registry.loader(DummyClass,
                          version=1,
                          class_hash='d2498176fad81ad017d1b0875eeeeb1b')
    def _load_dummy_class_v1(_):
        pass

    charon.testing.ast_hash.test_loaders_version(charon.Codec([test_registry]))
예제 #3
0
def test_dumpers_version_test_builtin():
    # pylint: disable=unused-variable
    test_registry = charon.CodecRegistry()

    @test_registry.dumper(set,
                          version=1,
                          class_hash='d2498176fad81ad017d1b0875eeeeb1b')
    def _load_set_v1(_):
        pass

    charon.testing.ast_hash.test_dumpers_version(charon.Codec([test_registry]))
예제 #4
0
def test_dumpers_version_test_invalid():
    # pylint: disable=unused-variable
    test_registry = charon.CodecRegistry()

    @test_registry.dumper(DummyClass, version=1, class_hash='invalid_hash')
    def _load_dummy_class_v1(_):
        pass

    with pytest.raises(AssertionError) as e:
        charon.testing.ast_hash.test_dumpers_version(
            charon.Codec([test_registry]))
    assert str(
        e.value
    ) == "DummyClass dumper has invalid hash 'invalid_hash', use `charon_ast_hash` to get current hash"
예제 #5
0
파일: base.py 프로젝트: qntln/charon
def test_codec():
    # pylint: disable=unused-variable
    test_registry = charon.CodecRegistry()

    @test_registry.dumper(DummyClass, version=1)
    def _dump_dummy_class(obj):
        return obj.version

    @test_registry.loader(DummyClass, version=1)
    def _load_dummy_class(data):
        return DummyClass(data)

    @test_registry.dumper(DummyClass2, version=1)
    def _dump_dummy_class2(obj):
        return obj.version

    @test_registry.loader(DummyClass2, version=1)
    def _load_dummy_class2(data):
        return DummyClass(data + 1)

    return charon.Codec([test_registry])
예제 #6
0
def test_codec_registry_missing_dumper(test_registry):
    with pytest.raises(KeyError) as e:
        test_registry.dump(charon.Codec())

    assert str(e.value) == "'Cannot dump object of type: Codec missing dumper'"
예제 #7
0
def test_codec_registry_add_dumper(test_registry):
    assert test_registry.dumpable(charon.CodecRegistry()) is True
    assert test_registry.dumpable(charon.Codec()) is False