コード例 #1
0
ファイル: POWCLITest.py プロジェクト: jaideep-seth/PyOpenWorm
def test_translate_data_source_loader(self):
    with connect(p(self.testdir, '.pow', 'pow.conf')) as conn:
        with transaction.manager:
            # Create data sources
            ctx = Context(ident='http://example.org/context', conf=conn.conf)
            ctx(LFDS)(
                ident='http://example.org/lfds',
                file_name='Merged_Nuclei_Stained_Worm.zip',
                torrent_file_name='d9da5ce947c6f1c127dfcdc2ede63320.torrent')

            class DT(DataTranslator):
                class_context = ctx.identifier
                input_type = LFDS
                output_type = LFDS
                translator_identifier = 'http://example.org/trans1'

                def translate(source):
                    print(source.full_path())
                    return source

            ctx.mapper.process_class(DT)
            dt = ctx(DT)()
            # Create a translator
            ctx_id = conn.conf['data_context_id']
            DT.definition_context.save(conn.conf['rdf.graph'])
            main_ctx = Context(ident=ctx_id, conf=conn.conf)
            main_ctx.add_import(ctx)
            main_ctx.save_imports()
            ctx.save()

    # Do translation
    assertRegexpMatches(
        self.sh(
            'pow translate http://example.org/trans1 http://example.org/lfds'),
        r'Merged_Nuclei_Stained_Worm.zip')
コード例 #2
0
ファイル: POWCLITest.py プロジェクト: jaideep-seth/PyOpenWorm
def test_translator_list(self):
    expected = URIRef('http://example.org/trans1')
    with connect(p(self.testdir, '.pow', 'pow.conf')) as conn:
        with transaction.manager:
            # Create data sources
            ctx = Context(ident='http://example.org/context', conf=conn.conf)

            class DT(DataTranslator):
                class_context = ctx.identifier
                translator_identifier = expected

                def translate(source):
                    pass

            ctx.mapper.process_class(DT)

            DT.definition_context.save(conn.conf['rdf.graph'])
            # Create a translator
            dt = ctx(DT)()

            ctx_id = conn.conf['data_context_id']
            main_ctx = Context(ident=ctx_id, conf=conn.conf)
            main_ctx.add_import(ctx)
            main_ctx.save_imports()
            ctx.save()

    # List translators
    assertRegexpMatches(
        self.sh('pow translator list'),
        re.compile('^' + expected.n3() + '$', flags=re.MULTILINE))