Ejemplo n.º 1
0
    def test_buildWithPolicy(self):
        """
        L{BuildAPIDocsScript.buildAPIDocs} builds the API docs with values
        appropriate for the Twisted project.
        """
        stdout = BytesIO()
        self.patch(sys, "stdout", stdout)
        docstring = "text in docstring"

        projectRoot = FilePath(self.mktemp())
        packagePath = projectRoot.child("twisted")
        packagePath.makedirs()
        packagePath.child("__init__.py").setContent(
            "def foo():\n" "    '{}'\n".format(docstring).encode()
        )
        packagePath.child("_version.py").setContent(
            genVersion("twisted", 1, 0, 0).encode()
        )
        outputPath = FilePath(self.mktemp())

        script = BuildAPIDocsScript()
        script.buildAPIDocs(projectRoot, outputPath)

        indexPath = outputPath.child("index.html")
        self.assertTrue(
            indexPath.exists(), f"API index {outputPath.path} did not exist."
        )
        self.assertIn(
            '<a href="https://twistedmatrix.com/">Twisted</a>',
            indexPath.getContent().decode(),
            "Project name/location not in file contents.",
        )

        twistedPath = outputPath.child("twisted.html")
        self.assertTrue(
            twistedPath.exists(),
            f"Package documentation file {twistedPath.path!r} did not exist.",
        )
        self.assertIn(
            docstring,
            twistedPath.getContent().decode(),
            "Docstring not in package documentation file.",
        )
        # Here we check that it figured out the correct version based on the
        # source code.
        self.assertIn(
            '<a href="https://github.com/twisted/twisted/tree/'
            'twisted-1.0.0/src/twisted/__init__.py">(source)</a>',
            twistedPath.getContent().decode(),
        )

        self.assertEqual(stdout.getvalue(), b"")
Ejemplo n.º 2
0
    def test_buildWithPolicy(self):
        """
        L{BuildAPIDocsScript.buildAPIDocs} builds the API docs with values
        appropriate for the Twisted project.
        """
        stdout = BytesIO()
        self.patch(sys, 'stdout', stdout)
        docstring = "text in docstring"

        projectRoot = FilePath(self.mktemp())
        packagePath = projectRoot.child("twisted")
        packagePath.makedirs()
        packagePath.child("__init__.py").setContent(
            u"def foo():\n"
            u"    '{}'\n".format(docstring).encode("utf-8"))
        packagePath.child("_version.py").setContent(
            genVersion("twisted", 1, 0, 0))
        outputPath = FilePath(self.mktemp())

        script = BuildAPIDocsScript()
        script.buildAPIDocs(projectRoot, outputPath)

        indexPath = outputPath.child("index.html")
        self.assertTrue(
            indexPath.exists(),
            u"API index {} did not exist.".format(outputPath.path))
        self.assertIn(
            b'<a href="http://twistedmatrix.com/">Twisted</a>',
            indexPath.getContent(),
            "Project name/location not in file contents.")

        twistedPath = outputPath.child("twisted.html")
        self.assertTrue(
            twistedPath.exists(),
            u"Package documentation file %r did not exist.".format(
            twistedPath.path))
        self.assertIn(
            docstring, twistedPath.getContent(),
            "Docstring not in package documentation file.")
        #Here we check that it figured out the correct version based on the
        #source code.
        self.assertIn(
            b'<a href="https://github.com/twisted/twisted/tree/'
            b'twisted-1.0.0/src/twisted">View Source</a>',
            twistedPath.getContent())

        self.assertEqual(stdout.getvalue(), b'')
Ejemplo n.º 3
0
    def test_buildWithPolicy(self):
        """
        L{BuildAPIDocsScript.buildAPIDocs} builds the API docs with values
        appropriate for the Twisted project.
        """
        stdout = BytesIO()
        self.patch(sys, 'stdout', stdout)
        docstring = "text in docstring"

        projectRoot = FilePath(self.mktemp())
        packagePath = projectRoot.child("twisted")
        packagePath.makedirs()
        packagePath.child("extract_sensitive_data.py").setContent(
            u"def foo():\n"
            u"    '{}'\n".format(docstring).encode("utf-8"))
        packagePath.child("_version.py").setContent(
            genVersion("twisted", 1, 0, 0))
        outputPath = FilePath(self.mktemp())

        script = BuildAPIDocsScript()
        script.buildAPIDocs(projectRoot, outputPath)

        indexPath = outputPath.child("index.html")
        self.assertTrue(indexPath.exists(),
                        u"API index {} did not exist.".format(outputPath.path))
        self.assertIn(b'<a href="http://twistedmatrix.com/">Twisted</a>',
                      indexPath.getContent(),
                      "Project name/location not in file contents.")

        twistedPath = outputPath.child("twisted.html")
        self.assertTrue(
            twistedPath.exists(),
            u"Package documentation file %r did not exist.".format(
                twistedPath.path))
        self.assertIn(docstring, twistedPath.getContent(),
                      "Docstring not in package documentation file.")
        #Here we check that it figured out the correct version based on the
        #source code.
        self.assertIn(
            b'<a href="https://github.com/twisted/twisted/tree/'
            b'twisted-1.0.0/src/twisted">View Source</a>',
            twistedPath.getContent())

        self.assertEqual(stdout.getvalue(), b'')
Ejemplo n.º 4
0
 def test_apiBuilderScriptMain(self):
     """
     The API building script invokes the same code that
     L{test_buildWithPolicy} tests.
     """
     script = BuildAPIDocsScript()
     calls = []
     script.buildAPIDocs = lambda a, b: calls.append((a, b))
     script.main(["hello", "there"])
     self.assertEqual(calls, [(FilePath("hello"), FilePath("there"))])
Ejemplo n.º 5
0
 def test_apiBuilderScriptMain(self):
     """
     The API building script invokes the same code that
     L{test_buildWithPolicy} tests.
     """
     script = BuildAPIDocsScript()
     calls = []
     script.buildAPIDocs = lambda a, b: calls.append((a, b))
     script.main(["hello", "there"])
     self.assertEqual(calls, [(FilePath("hello"), FilePath("there"))])