示例#1
0
    def test_get_content_from_pan(self):
        """Test get_content_from_pan function."""
        # Test with empty pan input file.
        self.assertEqual(panh.get_content_from_pan("test/testdata/pan_empty_input.pan"), {})

        expectedresult = {'functions':
                          [{'args': ['first number to add',
                                     'second number to add'],
                            'name': 'add',
                            'desc': 'simple addition of two numbers'}],
                          'types': [
                              {'fields': [
                                  {'range': '0..1',
                                   'required': 'true',
                                   'type': 'long',
                                   'name': 'debug',
                                   'desc': 'Test long.'},
                                  {'required': 'false',
                                   'type': 'string',
                                   'name': 'ca_dir',
                                   'desc': 'Test string'}],
                               'name': 'testtype',
                               'desc': 'test type.'}]}

        # Test with valid input.
        self.assertEqual(panh.get_content_from_pan("test/testdata/pan_annotated_schema.pan"), expectedresult)
示例#2
0
    def test_get_content_from_pan(self):
        """Test get_content_from_pan function."""
        # Test with empty pan input file.
        self.assertEqual(panh.get_content_from_pan("test/testdata/pan_empty_input.pan"), {})

        expectedresult = {'functions':
                          [{'args': ['first number to add',
                                     'second number to add'],
                            'name': 'add',
                            'desc': 'simple addition of two numbers'}],
                          'types': [
                              {'fields': [
                                  {'name': 'debug',
                                   'default': '0',
                                   'required': 'true',
                                   'range': '0..1',
                                   'type': 'long',
                                   'desc': 'Test long.'},
                                  {'required': 'false',
                                   'type': 'string',
                                   'name': 'ca_dir',
                                   'desc': 'Test string'},
                                  {'default': 'testdefault',
                                   'required': 'true',
                                   'type': 'string',
                                   'name': 'def',
                                   'desc': 'Test default'}],
                               'name': 'testtype',
                               'desc': 'test type.'}]}
        # Test with valid input.
        self.assertEqual(panh.get_content_from_pan("test/testdata/pan_annotated_schema.pan"), expectedresult)
示例#3
0
    def test_render_template(self):
        """Test render_template function."""
        content = panh.get_content_from_pan("test/testdata/pan_annotated_schema.pan")
        testfile = open(os.path.join(self.tmpdir, "test.md"), 'w')

        output = panh.render_template(content, "component-test")
        print output
        for line in output:
            testfile.write(line)
        testfile.close()

        self.assertTrue(filecmp.cmp("test/testdata/markdown_from_pan.md", testfile.name))

        # Test with only fields
        content = {'functions': [{'args': ['first number to add'], 'name': 'add'}]}

        output = panh.render_template(content, "component-test")
        print output

        expectedoutput = "\n### Functions\n\n - add\n    - Arguments:\n        - first number to add\n"
        self.assertEquals(output, expectedoutput)

        # Test with only Types
        content = {'types': [{'fields': [{'required': 'false', 'type': 'string', 'name': 'ca'}], 'name': 'testtype'}]}
        output = panh.render_template(content, "component-test")
        print output
        expectedoutput = "\n### Types\n\n - `/software/component-test/testtype`\n    - `/software/component-test/testtype/ca`\n\
        - Optional\n        - Type: string\n"
        self.assertEquals(output, expectedoutput)
示例#4
0
    def test_render_template(self):
        """Test render_template function."""
        content = panh.get_content_from_pan("test/testdata/pan_annotated_schema.pan")
        testfile = open(os.path.join(self.tmpdir, "test.md"), 'w')

        output = panh.render_template(content, "component-test")
        print output
        for line in output:
            testfile.write(line)
        testfile.close()

        self.assertTrue(filecmp.cmp("test/testdata/markdown_from_pan.md", testfile.name))

        # Test with only fields
        content = {'functions': [{'args': ['first number to add'], 'name': 'add'}]}

        output = panh.render_template(content, "component-test")
        print output

        expectedoutput = "\n### Functions\n\n - add\n    - Arguments:\n        - first number to add\n"
        self.assertEquals(output, expectedoutput)

        # Test with only Types
        content = {'types': [{'fields': [{'required': 'false', 'type': 'string', 'name': 'ca'}], 'name': 'testtype'}]}
        output = panh.render_template(content, "component-test")
        print output
        expectedoutput = "\n### Types\n\n - `/software/component-test/testtype`\n    - `/software/component-test/testtype/ca`\n\
        - Optional\n        - Type: string\n"
        self.assertEquals(output, expectedoutput)
示例#5
0
    def test_variables(self):
        """Test basic variable in schema."""

        content = panh.get_content_from_pan(
            "test/testdata/pan_schema_variables.pan")
        self.assertEquals(
            content, {
                'functions': [],
                'variables': [{
                    'name': 'FREEIPA_AII_MODULE_NAME'
                }],
                'types': []
            })

        testdir = os.path.join(self.tmpdir, "testdata")
        testfile = os.path.join(testdir, "pan_schema_variables.pan")
        os.makedirs(testdir)
        shutil.copy("test/testdata/pan_schema_variables.pan", testfile)
        testoutput = panh.rst_from_pan(testfile, "title", False, False)

        self.assertEquals(
            testoutput,
            u'#####\ntitle\n#####\n\nVariables\n---------\n\n - FREEIPA_AII_MODULE_NAME\n'
        )