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"))])
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"")
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'')
def test_apiBuilderScriptMainRequiresTwoArguments(self): """ SystemExit is raised when the incorrect number of command line arguments are passed to the API building script. """ script = BuildAPIDocsScript() self.assertRaises(SystemExit, script.main, []) self.assertRaises(SystemExit, script.main, ["foo"]) self.assertRaises(SystemExit, script.main, ["foo", "bar", "baz"])
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'')
#!c:\python27\python.exe # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. # This script is not meant to be distributed to users of Twisted. # It is only for use in making upstream Twisted releases. import sys from twisted.python._release import BuildAPIDocsScript BuildAPIDocsScript().main(sys.argv[1:])