Exemple #1
0
def test_string_prov_export():
    clear_topic_tree()

    importStr = '''
        """Tree docs, can be anything you want."""

        class root_topic_1:
            """Root topic 1."""

            class subtopic_1:
                """
                Sub topic 1 of root topic. Docs rely on one
                blank line for topic doc, and indentation for
                each argument doc.
                """

                def msgDataSpec(arg1, arg2=None):
                    """
                    - arg1: some multiline doc
                        for arg1
                    - arg2: some multiline doc
                        for arg2
                    """
                    pass

        class root_topic_2:
            """Root topic 2."""

        '''
    pub.clearTopicDefnProviders()
    provider = pub.addTopicDefnProvider(importStr, pub.TOPIC_TREE_FROM_STRING)
    treeDoc = provider.getTreeDoc()
    assert treeDoc == """Tree docs, can be anything you want."""
    root = topicMgr.getOrCreateTopic('root_topic_1.subtopic_1')
    assert root is not None
    assert topicMgr.getOrCreateTopic('root_topic_2').hasMDS()

    # few sanity checks
    def sub_1(arg1, arg2=None):
        pass

    assert root.hasMDS()
    assert pub.isValid(sub_1, 'root_topic_1.subtopic_1')

    # export tree
    exported = pub.exportTopicTreeSpec(rootTopic='root_topic_1',
                                       moduleDoc=treeDoc)
    # print(exported)

    expectExport = '''\
        # Automatically generated by TopicTreeSpecPrinter(**kwargs).
        # The kwargs were:
        # - fileObj: StringIO
        # - footer: '# End of topic tree definition. Note that application may l...'
        # - indentStep: 4
        # - treeDoc: 'Tree docs, can be anything you want....'
        # - width: 70


        """
        Tree docs, can be anything you want.
        """


        class root_topic_1:
            """
            Root topic 1.
            """

            class subtopic_1:
                """
                Sub topic 1 of root topic. Docs rely on one
                blank line for topic doc, and indentation for
                each argument doc.
                """

                def msgDataSpec(arg1, arg2=None):
                    """
                    - arg1: some multiline doc
                        for arg1
                    - arg2: some multiline doc
                        for arg2
                    """


        # End of topic tree definition. Note that application may load
        # more than one definitions provider.
        '''

    # check there are no differences
    from difflib import context_diff, ndiff
    diffs = ndiff(dedent(expectExport).splitlines(), exported.splitlines())
    diffs = [d for d in diffs if not d.startswith(' ')]
    assert diffs == ['- ', '+         ']

    # now for module:
    provider = pub.addTopicDefnProvider('test4_prov_module_expect')
    pub.instantiateAllDefinedTopics(provider)
    modDoc = provider.getTreeDoc()
    assert modDoc.startswith('\nTree docs, can be anything you')
    pub.exportTopicTreeSpec('test4_prov_module_actual',
                            rootTopic='root_topic_1b',
                            moduleDoc=treeDoc)
    lines1 = open('test4_prov_module_actual.py', 'r').readlines()
    lines2 = open('test4_prov_module_expect.py', 'r').readlines()
    diffs = ndiff(lines1, lines2)
    diffs = [d for d in diffs if not d.startswith(' ')]
    assert not list(diffs) or list(diffs) == [
        '- # - fileObj: TextIOWrapper\n', '+ # - fileObj: file\n'
    ]
    Path('test4_prov_module_actual.py').unlink()
Exemple #2
0
def start_application():
    PySpecApp().run()
    pub.exportTopicTreeSpec('test')
Exemple #3
0
# ***** actual application **********

print('Using "kwargs" messaging protocol of pubsub v3')

try:
    print('------- init ----------')

    pub.addTopicDefnProvider(kwargs_topics, pub.TOPIC_TREE_FROM_CLASS)
    pub.setTopicUnspecifiedFatal()

    import kwargs_listeners
    import kwargs_senders as senders

    print('-----------------------')
    senders.doSomething1()
    senders.doSomething2()

    print('------- done ----------')

    print('Exporting topic tree to', kwargs_topics.__name__)
    pub.exportTopicTreeSpec('kwargs_topics_out')

except Exception:
    import traceback

    traceback.print_exc()
    print(pub.exportTopicTreeSpec())

print('------ exiting --------')
import arg1_topics

#***** actual application **********

print_('Using "arg1" messaging protocol of pubsub v3')

try:
    print_('------- init ----------')

    pub.addTopicDefnProvider( arg1_topics, pub.TOPIC_TREE_FROM_CLASS )
    pub.setTopicUnspecifiedFatal()

    import arg1_listeners
    import arg1_senders as senders

    print_('-----------------------')
    senders.doSomething1()
    senders.doSomething2()

    print_('------- done ----------')

    print_('Exporting topic tree to', arg1_topics.__name__)
    pub.exportTopicTreeSpec('arg1_topics_out')

except Exception:
    import traceback
    traceback.print_exc()
    print_(pub.exportTopicTreeSpec())

print_('------ exiting --------')
Exemple #5
0
import arg1_topics

#***** actual application **********

print_('Using "arg1" messaging protocol of pubsub v3')

try:
    print_('------- init ----------')

    pub.addTopicDefnProvider(arg1_topics, pub.TOPIC_TREE_FROM_CLASS)
    pub.setTopicUnspecifiedFatal()

    import arg1_listeners
    import arg1_senders as senders

    print_('-----------------------')
    senders.doSomething1()
    senders.doSomething2()

    print_('------- done ----------')

    print_('Exporting topic tree to', arg1_topics.__name__)
    pub.exportTopicTreeSpec('arg1_topics_out')

except Exception:
    import traceback
    traceback.print_exc()
    print_(pub.exportTopicTreeSpec())

print_('------ exiting --------')
Exemple #6
0
def test_string_prov_export():
    clear_topic_tree()

    importStr = '''
        """Tree docs, can be anything you want."""

        class root_topic_1:
            """Root topic 1."""

            class subtopic_1:
                """
                Sub topic 1 of root topic. Docs rely on one
                blank line for topic doc, and indentation for
                each argument doc.
                """

                def msgDataSpec(arg1, arg2=None):
                    """
                    - arg1: some multiline doc
                        for arg1
                    - arg2: some multiline doc
                        for arg2
                    """
                    pass

        class root_topic_2:
            """Root topic 2."""

        '''
    pub.clearTopicDefnProviders()
    provider = pub.addTopicDefnProvider(importStr, pub.TOPIC_TREE_FROM_STRING)
    treeDoc = provider.getTreeDoc()
    assert treeDoc == """Tree docs, can be anything you want."""
    root = topicMgr.getOrCreateTopic('root_topic_1.subtopic_1')
    assert root is not None
    assert topicMgr.getOrCreateTopic('root_topic_2').hasMDS()

    # few sanity checks
    def sub_1(arg1, arg2=None): pass

    assert root.hasMDS()
    assert pub.isValid(sub_1, 'root_topic_1.subtopic_1')

    # export tree
    exported = pub.exportTopicTreeSpec(rootTopic='root_topic_1', moduleDoc=treeDoc)
    # print(exported)

    expectExport = '''\
        # Automatically generated by TopicTreeSpecPrinter(**kwargs).
        # The kwargs were:
        # - fileObj: StringIO
        # - footer: '# End of topic tree definition. Note that application may l...'
        # - indentStep: 4
        # - treeDoc: 'Tree docs, can be anything you want....'
        # - width: 70


        """
        Tree docs, can be anything you want.
        """


        class root_topic_1:
            """
            Root topic 1.
            """

            class subtopic_1:
                """
                Sub topic 1 of root topic. Docs rely on one
                blank line for topic doc, and indentation for
                each argument doc.
                """

                def msgDataSpec(arg1, arg2=None):
                    """
                    - arg1: some multiline doc
                        for arg1
                    - arg2: some multiline doc
                        for arg2
                    """


        # End of topic tree definition. Note that application may load
        # more than one definitions provider.
        '''

    # check there are no differences
    from difflib import context_diff, ndiff
    diffs = ndiff(dedent(expectExport).splitlines(), exported.splitlines())
    diffs = [d for d in diffs if not d.startswith(' ')]
    assert diffs == ['- ', '+         ']

    # now for module:
    provider = pub.addTopicDefnProvider('test4_prov_module_expect')
    pub.instantiateAllDefinedTopics(provider)
    modDoc = provider.getTreeDoc()
    assert modDoc.startswith('\nTree docs, can be anything you')
    pub.exportTopicTreeSpec('test4_prov_module_actual',
                            rootTopic='root_topic_1b', moduleDoc=treeDoc)
    lines1 = open('test4_prov_module_actual.py', 'r').readlines()
    lines2 = open('test4_prov_module_expect.py', 'r').readlines()
    diffs = ndiff(lines1, lines2)
    diffs = [d for d in diffs if not d.startswith(' ')]
    assert not list(diffs) or list(diffs) == ['- # - fileObj: TextIOWrapper\n', '+ # - fileObj: file\n']
    Path('test4_prov_module_actual.py').unlink()