Esempio n. 1
0
    def test_default(self):
        with directory() as tmp:
            # given
            tmp.dir('documentary')
            tmp.store(['src'], '')
            tmp.store(['documentary', 'src'], '')

            # when
            doc, root, template, output = resolve_paths(
                args(root=tmp(), template='src'))

            # then
            self.assertEqual(
                tmp('documentary'),
                doc,
                msg='Failed to assert that documentary path is returned')
            self.assertEqual(
                tmp(),
                root,
                msg=
                'Failed to assert that root path is current working directory')
            self.assertEqual(
                'src',
                template,
                msg=
                'Failed to assert template is joined with current working directory'
            )
            self.assertEqual(
                root,
                output,
                msg="Failed to assert that output path is root path")
Esempio n. 2
0
    def test_should_return_default_for_missing_fragment(self):
        with directory() as tmp:
            # when
            result = fragment(tmp.join('folder'), 'missing', default=lambda: 'returned')

            # then
            self.assertEqual('returned', result)
Esempio n. 3
0
    def test_many(self):
        with stubbed_output() as lines:
            with directory() as tmp:
                # when
                document_many(documentary_path=resource('input/documentary'),
                              root_path=resource('input'),
                              templates_path='src',
                              output_path=tmp.join('output'))

                # then
                with open(resource('expected/preg.php'), 'r') as expected:
                    self.assertEqual(expected.read(),
                                     tmp.open('output/src/SafeRegex/preg.php'))

                with open(resource('expected/Pattern.php'), 'r') as expected:
                    self.assertEqual(
                        expected.read(),
                        tmp.open('output/src/CleanRegex/Pattern.php'))

                self.assertPathsMatch(
                    actual=lines(),
                    expected=[
                        f'File "{resource("input")}/src/SafeRegex/preg.php" documented',
                        f'File "{resource("input")}/src/CleanRegex/Pattern.php" documented',
                    ])
Esempio n. 4
0
    def test_should_traverse_fallback(self):
        with directory() as tmp:
            # given
            tmp.store('folder/first.html', 'Foo')

            # when
            result = fragment_fallback(tmp.join('folder'), 'first', 'second', tmp.join())

            # then
            self.assertEqual(result, "Foo")
Esempio n. 5
0
    def test_should_discover_itself(self):
        with directory() as tmp:
            # given
            tmp.store('src/app/first.py', 'template')

            # when
            result = discover_templates('src/app/first.py', tmp.join(), tmp.join('documentary'))

            # then
            self.assertEqual(['src/app/first.py'], result)
Esempio n. 6
0
    def test_should_raise_for_no_documentary(self):
        with directory() as tmp:
            # given
            tmp.store('src/file', 'template')

            # when
            with self.assertRaises(TemplatesDiscoveryException) as error:
                discover_templates('src', tmp.join(), tmp.join('documentary'))

            # then
            self.assertEqual("File/folder 'src' is not documented", str(error.exception))
Esempio n. 7
0
    def test_missing_files(self):
        with directory() as tmp:
            # when
            details, _ = load_details(
                declaration=tmp.join('missing.json'),
                decorations=tmp.join('missing.json'),
                definitions=tmp.join('missing.json'),
            )

            # then
            self.assertEqual({}, details)
Esempio n. 8
0
    def test_should_raise_for_missing_file(self):
        with directory() as tmp:
            # given
            tmp.store('src/app/first.py', 'template')

            # when
            with self.assertRaises(FileNotFoundError) as error:
                discover_templates('src/app/second.py', tmp.join(), tmp.join('documentary'))

            # then
            self.assertEqual(str(error.exception), "File/folder 'src/app/second.py' does not exist")
Esempio n. 9
0
    def test_should_traverse_fallback_project(self):
        with directory() as tmp:
            # given
            tmp.store('project/fragment/second.html', 'Global')
            tmp.store('a/b/c/foo.html', '')

            # when
            result = fragment_fallback(tmp.join('a', 'b', 'c'), 'first', 'second', tmp.join())

            # then
            self.assertEqual(result, "Global")
Esempio n. 10
0
    def test_raise_for_missing_documentary(self):
        with directory() as tmp:
            # given
            with self.assertRaises(Exception) as error:
                # when
                resolve_paths(args(root=tmp(), template='src'))

            # then
            self.assertEqual(
                tmp.strip(str(error.exception)),
                'To generate documentation, navigate to a directory with "documentary" folder'
            )
Esempio n. 11
0
    def test_should_raise_for_not_documented_folder(self):
        with directory() as tmp:
            # given
            tmp.store('src/main/second.py', 'template file')
            tmp.dir('docs/src/test')

            # when
            with self.assertRaises(TemplatesDiscoveryException) as error:
                discover_templates('src/main', tmp.join(), documentary=tmp.join('docs'))

            # then
            self.assertEqual("File/folder 'src/main' is not documented", str(error.exception))
Esempio n. 12
0
    def test_raise_for_missing_template(self):
        with directory() as tmp:
            # given
            tmp.dir('documentary')

            # when
            with self.assertRaises(Exception) as error:
                # when
                resolve_paths(args(root=tmp(), template='src'))

            # then
            self.assertEqual(
                r"""Tried to documentation file "src", but it doesn't exist""",
                tmp.strip((str(error.exception))))
Esempio n. 13
0
    def test_raise_for_missing_documentation(self):
        with directory() as tmp:
            # given
            tmp.dir('documentary')
            tmp.store(['src'], '')

            # when
            with self.assertRaises(Exception) as error:
                # when
                resolve_paths(args(root=tmp(), template='src'))

            # then
            self.assertEqual(
                'Directory "src" is missing in documentary folder',
                str(error.exception))
Esempio n. 14
0
    def test_empty_files(self):
        with directory() as tmp:
            # given
            tmp.store('declaration.json', dumps({}))
            tmp.store('decorations.json', dumps({}))
            tmp.store('definitions.json', dumps({}))

            # when
            details, _ = load_details(
                declaration=tmp.join('declaration.json'),
                decorations=tmp.join('decorations.json'),
                definitions=tmp.join('definitions.json'),
            )

            # then
            self.assertEqual(second=details, first={})
Esempio n. 15
0
    def test_single(self):
        with stubbed_output() as lines:
            with directory() as tmp:
                # when
                document(
                    documentary_path=resource('input/documentary'),
                    documentation_path=resource(
                        'input/documentary/src/SafeRegex/preg.php'),
                    template_path=resource('input/src/SafeRegex/preg.php'),
                    output_path=tmp.join('preg.php'))

                # then
                with open(resource('expected/preg.php'), 'r') as expected:
                    self.assertEqual(expected.read(), tmp.open('preg.php'))

                self.assertEqual([
                    f'File "{resource("input/src/SafeRegex/preg.php")}" documented'
                ], lines())
Esempio n. 16
0
    def test_should_discover_children(self):
        with directory() as tmp:
            # given - templates
            tmp.store('src/main/second.py', 'template file')
            tmp.store('src/main/sub/first.py', 'template file')
            tmp.store('src/test/first.py', 'template file')
            # given - documents
            tmp.store('docs/src/main/first.py/definition.json', '{}')
            tmp.store('docs/src/main/second.py/definition.json', '{}')
            tmp.store('docs/src/main/sub/first.py/definition.json', '{}')
            tmp.store('docs/src/main/sub/second.py/definition.json', '{}')
            tmp.store('docs/src/test/first.py/definition.json', '{}')
            tmp.store('docs/src/test/second.py/definition.json', '{}')

            # when
            result = discover_templates('src', tmp.join(), documentary=tmp.join('docs'))

            # then
            self.assertPathsMatch(actual=result, expected=[
                'src/main/second.py',
                'src/main/sub/first.py',
                'src/test/first.py',
            ])
Esempio n. 17
0
 def test_should_raise_for_missing_fragment(self):
     with directory() as tmp:
         # then
         self.assertRaises(MissingFragmentException, lambda: fragment(tmp.join('folder'), 'missing'))