code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_chdir(self):
"""
Test that the runChdirSafe is actually safe, i.e., it still
changes back to the original directory even if an error is
raised.
"""
cwd = os.getcwd()
def chAndBreak():
os.mkdir('releaseCh')
os.chdir('releaseCh')
1 // 0
self.assertRaises(ZeroDivisionError,
release.runChdirSafe, chAndBreak)
self.assertEqual(cwd, os.getcwd()) | Test that the runChdirSafe is actually safe, i.e., it still
changes back to the original directory even if an error is
raised. | test_chdir | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_replaceInFile(self):
"""
L{replaceInFile} replaces data in a file based on a dict. A key from
the dict that is found in the file is replaced with the corresponding
value.
"""
content = 'foo\nhey hey $VER\nbar\n'
with open('release.replace', 'w') as outf:
outf.write(content)
expected = content.replace('$VER', '2.0.0')
replaceInFile('release.replace', {'$VER': '2.0.0'})
with open('release.replace') as f:
self.assertEqual(f.read(), expected)
expected = expected.replace('2.0.0', '3.0.0')
replaceInFile('release.replace', {'2.0.0': '3.0.0'})
with open('release.replace') as f:
self.assertEqual(f.read(), expected) | L{replaceInFile} replaces data in a file based on a dict. A key from
the dict that is found in the file is replaced with the corresponding
value. | test_replaceInFile | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def doNotFailOnNetworkError(func):
"""
A decorator which makes APIBuilder tests not fail because of intermittent
network failures -- mamely, APIBuilder being unable to get the "object
inventory" of other projects.
@param func: The function to decorate.
@return: A decorated function which won't fail if the object inventory
fetching fails.
"""
@functools.wraps(func)
def wrapper(*a, **kw):
try:
func(*a, **kw)
except FailTest as e:
if e.args[0].startswith("'Failed to get object inventory from "):
raise SkipTest(
("This test is prone to intermittent network errors. "
"See ticket 8753. Exception was: {!r}").format(e))
raise
return wrapper | A decorator which makes APIBuilder tests not fail because of intermittent
network failures -- mamely, APIBuilder being unable to get the "object
inventory" of other projects.
@param func: The function to decorate.
@return: A decorated function which won't fail if the object inventory
fetching fails. | doNotFailOnNetworkError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_skipsOnAssertionError(self):
"""
When the test raises L{FailTest} and the assertion failure starts with
"'Failed to get object inventory from ", the test will be skipped
instead.
"""
@doNotFailOnNetworkError
def inner():
self.assertEqual("Failed to get object inventory from blah", "")
try:
inner()
except Exception as e:
self.assertIsInstance(e, SkipTest) | When the test raises L{FailTest} and the assertion failure starts with
"'Failed to get object inventory from ", the test will be skipped
instead. | test_skipsOnAssertionError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_doesNotSkipOnDifferentError(self):
"""
If there is a L{FailTest} that is not the intersphinx fetching error,
it will be passed through.
"""
@doNotFailOnNetworkError
def inner():
self.assertEqual("Error!!!!", "")
try:
inner()
except Exception as e:
self.assertIsInstance(e, FailTest) | If there is a L{FailTest} that is not the intersphinx fetching error,
it will be passed through. | test_doesNotSkipOnDifferentError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_build(self):
"""
L{APIBuilder.build} writes an index file which includes the name of the
project specified.
"""
stdout = BytesIO()
self.patch(sys, 'stdout', stdout)
projectName = "Foobar"
packageName = "quux"
projectURL = "scheme:project"
sourceURL = "scheme:source"
docstring = "text in docstring"
privateDocstring = "should also appear in output"
inputPath = FilePath(self.mktemp()).child(packageName)
inputPath.makedirs()
inputPath.child("__init__.py").setContent(
u"def foo():\n"
u" '{}'\n"
u"def _bar():\n"
u" '{}'".format(docstring, privateDocstring).encode("utf-8"))
outputPath = FilePath(self.mktemp())
builder = APIBuilder()
builder.build(projectName, projectURL, sourceURL, inputPath,
outputPath)
indexPath = outputPath.child("index.html")
self.assertTrue(
indexPath.exists(),
"API index %r did not exist." % (outputPath.path,))
self.assertIn(
'<a href="%s">%s</a>' % (projectURL, projectName),
indexPath.getContent(),
"Project name/location not in file contents.")
quuxPath = outputPath.child("quux.html")
self.assertTrue(
quuxPath.exists(),
"Package documentation file %r did not exist." % (quuxPath.path,))
self.assertIn(
docstring, quuxPath.getContent(),
"Docstring not in package documentation file.")
self.assertIn(
'<a href="%s/%s">View Source</a>' % (sourceURL, packageName),
quuxPath.getContent())
self.assertIn(
'<a class="functionSourceLink" href="%s/%s/__init__.py#L1">' % (
sourceURL, packageName),
quuxPath.getContent())
self.assertIn(privateDocstring, quuxPath.getContent())
# There should also be a page for the foo function in quux.
self.assertTrue(quuxPath.sibling('quux.foo.html').exists())
self.assertEqual(stdout.getvalue(), '') | L{APIBuilder.build} writes an index file which includes the name of the
project specified. | test_build | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
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'') | L{BuildAPIDocsScript.buildAPIDocs} builds the API docs with values
appropriate for the Twisted project. | test_buildWithPolicy | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_buildWithDeprecated(self):
"""
The templates and System for Twisted includes adding deprecations.
"""
stdout = BytesIO()
self.patch(sys, 'stdout', stdout)
projectName = "Foobar"
packageName = "quux"
projectURL = "scheme:project"
sourceURL = "scheme:source"
docstring = "text in docstring"
privateDocstring = "should also appear in output"
inputPath = FilePath(self.mktemp()).child(packageName)
inputPath.makedirs()
inputPath.child("__init__.py").setContent(
u"from twisted.python.deprecate import deprecated\n"
u"from incremental import Version\n"
u"@deprecated(Version('Twisted', 15, 0, 0), "
u"'Baz')\n"
u"def foo():\n"
u" '{}'\n"
u"from twisted.python import deprecate\n"
u"import incremental\n"
u"@deprecate.deprecated(incremental.Version('Twisted', 16, 0, 0))\n"
u"def _bar():\n"
u" '{}'\n"
u"@deprecated(Version('Twisted', 14, 2, 3), replacement='stuff')\n"
u"class Baz(object):\n"
u" pass"
u"".format(docstring, privateDocstring).encode("utf-8"))
outputPath = FilePath(self.mktemp())
builder = APIBuilder()
builder.build(projectName, projectURL, sourceURL, inputPath,
outputPath)
quuxPath = outputPath.child("quux.html")
self.assertTrue(
quuxPath.exists(),
"Package documentation file %r did not exist." % (quuxPath.path,))
self.assertIn(
docstring, quuxPath.getContent(),
"Docstring not in package documentation file.")
self.assertIn(
'foo was deprecated in Twisted 15.0.0; please use Baz instead.',
quuxPath.getContent())
self.assertIn(
'_bar was deprecated in Twisted 16.0.0.',
quuxPath.getContent())
self.assertIn(privateDocstring, quuxPath.getContent())
# There should also be a page for the foo function in quux.
self.assertTrue(quuxPath.sibling('quux.foo.html').exists())
self.assertIn(
'foo was deprecated in Twisted 15.0.0; please use Baz instead.',
quuxPath.sibling('quux.foo.html').getContent())
self.assertIn(
'Baz was deprecated in Twisted 14.2.3; please use stuff instead.',
quuxPath.sibling('quux.Baz.html').getContent())
self.assertEqual(stdout.getvalue(), '') | The templates and System for Twisted includes adding deprecations. | test_buildWithDeprecated | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
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"]) | SystemExit is raised when the incorrect number of command line
arguments are passed to the API building script. | test_apiBuilderScriptMainRequiresTwoArguments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
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"))]) | The API building script invokes the same code that
L{test_buildWithPolicy} tests. | test_apiBuilderScriptMain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_filePathDeltaSubdir(self):
"""
L{filePathDelta} can create a simple relative path to a child path.
"""
self.assertEqual(filePathDelta(FilePath("/foo/bar"),
FilePath("/foo/bar/baz")),
["baz"]) | L{filePathDelta} can create a simple relative path to a child path. | test_filePathDeltaSubdir | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_filePathDeltaSiblingDir(self):
"""
L{filePathDelta} can traverse upwards to create relative paths to
siblings.
"""
self.assertEqual(filePathDelta(FilePath("/foo/bar"),
FilePath("/foo/baz")),
["..", "baz"]) | L{filePathDelta} can traverse upwards to create relative paths to
siblings. | test_filePathDeltaSiblingDir | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_filePathNoCommonElements(self):
"""
L{filePathDelta} can create relative paths to totally unrelated paths
for maximum portability.
"""
self.assertEqual(filePathDelta(FilePath("/foo/bar"),
FilePath("/baz/quux")),
["..", "..", "baz", "quux"]) | L{filePathDelta} can create relative paths to totally unrelated paths
for maximum portability. | test_filePathNoCommonElements | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_filePathDeltaSimilarEndElements(self):
"""
L{filePathDelta} doesn't take into account final elements when
comparing 2 paths, but stops at the first difference.
"""
self.assertEqual(filePathDelta(FilePath("/foo/bar/bar/spam"),
FilePath("/foo/bar/baz/spam")),
["..", "..", "baz", "spam"]) | L{filePathDelta} doesn't take into account final elements when
comparing 2 paths, but stops at the first difference. | test_filePathDeltaSimilarEndElements | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def setUp(self):
"""
Set up a few instance variables that will be useful.
"""
self.builder = SphinxBuilder()
# set up a place for a fake sphinx project
self.twistedRootDir = FilePath(self.mktemp())
self.sphinxDir = self.twistedRootDir.child("docs")
self.sphinxDir.makedirs()
self.sourceDir = self.sphinxDir | Set up a few instance variables that will be useful. | setUp | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def createFakeSphinxProject(self):
"""
Create a fake Sphinx project for test purposes.
Creates a fake Sphinx project with the absolute minimum of source
files. This includes a single source file ('index.rst') and the
smallest 'conf.py' file possible in order to find that source file.
"""
self.sourceDir.child("conf.py").setContent(self.confContent.encode("utf-8"))
self.sourceDir.child("index.rst").setContent(self.indexContent.encode("utf-8")) | Create a fake Sphinx project for test purposes.
Creates a fake Sphinx project with the absolute minimum of source
files. This includes a single source file ('index.rst') and the
smallest 'conf.py' file possible in order to find that source file. | createFakeSphinxProject | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def verifyFileExists(self, fileDir, fileName):
"""
Helper which verifies that C{fileName} exists in C{fileDir} and it has
some content.
@param fileDir: A path to a directory.
@type fileDir: L{FilePath}
@param fileName: The last path segment of a file which may exist within
C{fileDir}.
@type fileName: L{str}
@raise: L{FailTest <twisted.trial.unittest.FailTest>} if
C{fileDir.child(fileName)}:
1. Does not exist.
2. Is empty.
3. In the case where it's a path to a C{.html} file, the
content looks like an HTML file.
@return: L{None}
"""
# check that file exists
fpath = fileDir.child(fileName)
self.assertTrue(fpath.exists())
# check that the output files have some content
fcontents = fpath.getContent()
self.assertTrue(len(fcontents) > 0)
# check that the html files are at least html-ish
# this is not a terribly rigorous check
if fpath.path.endswith('.html'):
self.assertIn(b"<body", fcontents) | Helper which verifies that C{fileName} exists in C{fileDir} and it has
some content.
@param fileDir: A path to a directory.
@type fileDir: L{FilePath}
@param fileName: The last path segment of a file which may exist within
C{fileDir}.
@type fileName: L{str}
@raise: L{FailTest <twisted.trial.unittest.FailTest>} if
C{fileDir.child(fileName)}:
1. Does not exist.
2. Is empty.
3. In the case where it's a path to a C{.html} file, the
content looks like an HTML file.
@return: L{None} | verifyFileExists | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_build(self):
"""
Creates and builds a fake Sphinx project using a L{SphinxBuilder}.
"""
self.createFakeSphinxProject()
self.builder.build(self.sphinxDir)
self.verifyBuilt() | Creates and builds a fake Sphinx project using a L{SphinxBuilder}. | test_build | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_main(self):
"""
Creates and builds a fake Sphinx project as if via the command line.
"""
self.createFakeSphinxProject()
self.builder.main([self.sphinxDir.parent().path])
self.verifyBuilt() | Creates and builds a fake Sphinx project as if via the command line. | test_main | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_warningsAreErrors(self):
"""
Creates and builds a fake Sphinx project as if via the command line,
failing if there are any warnings.
"""
output = StringIO()
self.patch(sys, "stdout", output)
self.createFakeSphinxProject()
with self.sphinxDir.child("index.rst").open("a") as f:
f.write(b"\n.. _malformed-link-target\n")
exception = self.assertRaises(
SystemExit,
self.builder.main, [self.sphinxDir.parent().path]
)
self.assertEqual(exception.code, 1)
self.assertIn("malformed hyperlink target", output.getvalue())
self.verifyBuilt() | Creates and builds a fake Sphinx project as if via the command line,
failing if there are any warnings. | test_warningsAreErrors | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def verifyBuilt(self):
"""
Verify that a sphinx project has been built.
"""
htmlDir = self.sphinxDir.sibling('doc')
self.assertTrue(htmlDir.isdir())
doctreeDir = htmlDir.child("doctrees")
self.assertFalse(doctreeDir.exists())
self.verifyFileExists(htmlDir, 'index.html')
self.verifyFileExists(htmlDir, 'genindex.html')
self.verifyFileExists(htmlDir, 'objects.inv')
self.verifyFileExists(htmlDir, 'search.html')
self.verifyFileExists(htmlDir, 'searchindex.js') | Verify that a sphinx project has been built. | verifyBuilt | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_failToBuild(self):
"""
Check that SphinxBuilder.build fails when run against a non-sphinx
directory.
"""
# note no fake sphinx project is created
self.assertRaises(CalledProcessError,
self.builder.build,
self.sphinxDir) | Check that SphinxBuilder.build fails when run against a non-sphinx
directory. | test_failToBuild | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_ensureIsWorkingDirectoryWithWorkingDirectory(self):
"""
Calling the C{ensureIsWorkingDirectory} VCS command's method on a valid
working directory doesn't produce any error.
"""
reposDir = self.makeRepository(self.tmpDir)
self.assertIsNone(
self.createCommand.ensureIsWorkingDirectory(reposDir)) | Calling the C{ensureIsWorkingDirectory} VCS command's method on a valid
working directory doesn't produce any error. | test_ensureIsWorkingDirectoryWithWorkingDirectory | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_ensureIsWorkingDirectoryWithNonWorkingDirectory(self):
"""
Calling the C{ensureIsWorkingDirectory} VCS command's method on an
invalid working directory raises a L{NotWorkingDirectory} exception.
"""
self.assertRaises(NotWorkingDirectory,
self.createCommand.ensureIsWorkingDirectory,
self.tmpDir) | Calling the C{ensureIsWorkingDirectory} VCS command's method on an
invalid working directory raises a L{NotWorkingDirectory} exception. | test_ensureIsWorkingDirectoryWithNonWorkingDirectory | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_statusClean(self):
"""
Calling the C{isStatusClean} VCS command's method on a repository with
no pending modifications returns C{True}.
"""
reposDir = self.makeRepository(self.tmpDir)
self.assertTrue(self.createCommand.isStatusClean(reposDir)) | Calling the C{isStatusClean} VCS command's method on a repository with
no pending modifications returns C{True}. | test_statusClean | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_statusNotClean(self):
"""
Calling the C{isStatusClean} VCS command's method on a repository with
no pending modifications returns C{False}.
"""
reposDir = self.makeRepository(self.tmpDir)
reposDir.child('some-file').setContent(b"something")
self.assertFalse(self.createCommand.isStatusClean(reposDir)) | Calling the C{isStatusClean} VCS command's method on a repository with
no pending modifications returns C{False}. | test_statusNotClean | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_remove(self):
"""
Calling the C{remove} VCS command's method remove the specified path
from the directory.
"""
reposDir = self.makeRepository(self.tmpDir)
testFile = reposDir.child('some-file')
testFile.setContent(b"something")
self.commitRepository(reposDir)
self.assertTrue(testFile.exists())
self.createCommand.remove(testFile)
testFile.restat(False) # Refresh the file information
self.assertFalse(testFile.exists(), "File still exists") | Calling the C{remove} VCS command's method remove the specified path
from the directory. | test_remove | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_export(self):
"""
The C{exportTo} VCS command's method export the content of the
repository as identical in a specified directory.
"""
structure = {
"README.rst": u"Hi this is 1.0.0.",
"twisted": {
"newsfragments": {
"README": u"Hi this is 1.0.0"},
"_version.py": genVersion("twisted", 1, 0, 0),
"web": {
"newsfragments": {
"README": u"Hi this is 1.0.0"},
"_version.py": genVersion("twisted.web", 1, 0, 0)}}}
reposDir = self.makeRepository(self.tmpDir)
self.createStructure(reposDir, structure)
self.commitRepository(reposDir)
exportDir = FilePath(self.mktemp()).child("export")
self.createCommand.exportTo(reposDir, exportDir)
self.assertStructure(exportDir, structure) | The C{exportTo} VCS command's method export the content of the
repository as identical in a specified directory. | test_export | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def makeRepository(self, root):
"""
Create a Git repository in the specified path.
@type root: L{FilePath}
@params root: The directory to create the Git repository into.
@return: The path to the repository just created.
@rtype: L{FilePath}
"""
_gitInit(root)
return root | Create a Git repository in the specified path.
@type root: L{FilePath}
@params root: The directory to create the Git repository into.
@return: The path to the repository just created.
@rtype: L{FilePath} | makeRepository | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def commitRepository(self, repository):
"""
Add and commit all the files from the Git repository specified.
@type repository: L{FilePath}
@params repository: The Git repository to commit into.
"""
runCommand(["git", "-C", repository.path, "add"] +
glob.glob(repository.path + "/*"))
runCommand(["git", "-C", repository.path, "commit", "-m", "hop"]) | Add and commit all the files from the Git repository specified.
@type repository: L{FilePath}
@params repository: The Git repository to commit into. | commitRepository | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_git(self):
"""
L{getRepositoryCommand} from a Git repository returns L{GitCommand}.
"""
_gitInit(self.repos)
cmd = getRepositoryCommand(self.repos)
self.assertIs(cmd, GitCommand) | L{getRepositoryCommand} from a Git repository returns L{GitCommand}. | test_git | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_unknownRepository(self):
"""
L{getRepositoryCommand} from a directory which doesn't look like a Git
repository produces a L{NotWorkingDirectory} exception.
"""
self.assertRaises(NotWorkingDirectory, getRepositoryCommand,
self.repos) | L{getRepositoryCommand} from a directory which doesn't look like a Git
repository produces a L{NotWorkingDirectory} exception. | test_unknownRepository | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_git(self):
"""
L{GitCommand} implements L{IVCSCommand}.
"""
self.assertTrue(IVCSCommand.implementedBy(GitCommand)) | L{GitCommand} implements L{IVCSCommand}. | test_git | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_noArgs(self):
"""
Too few arguments returns a failure.
"""
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([])
self.assertEqual(e.exception.args,
("Must specify one argument: the Twisted checkout",)) | Too few arguments returns a failure. | test_noArgs | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_diffFromTrunkNoNewsfragments(self):
"""
If there are changes from trunk, then there should also be a
newsfragment.
"""
runCommand(["git", "checkout", "-b", "mypatch"],
cwd=self.repo.path)
somefile = self.repo.child("somefile")
somefile.setContent(b"change")
runCommand(["git", "add", somefile.path, somefile.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "some file"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (1,))
self.assertEqual(logs[-1],
"No newsfragment found. Have you committed it?") | If there are changes from trunk, then there should also be a
newsfragment. | test_diffFromTrunkNoNewsfragments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_noChangeFromTrunk(self):
"""
If there are no changes from trunk, then no need to check the
newsfragments
"""
runCommand(["git", "checkout", "-b", "mypatch"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(
logs[-1],
"On trunk or no diffs from trunk; no need to look at this.") | If there are no changes from trunk, then no need to check the
newsfragments | test_noChangeFromTrunk | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_trunk(self):
"""
Running it on trunk always gives green.
"""
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(
logs[-1],
"On trunk or no diffs from trunk; no need to look at this.") | Running it on trunk always gives green. | test_trunk | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_release(self):
"""
Running it on a release branch returns green if there is no
newsfragments even if there are changes.
"""
runCommand(["git", "checkout", "-b", "release-16.11111-9001"],
cwd=self.repo.path)
somefile = self.repo.child("somefile")
somefile.setContent(b"change")
runCommand(["git", "add", somefile.path, somefile.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "some file"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(logs[-1],
"Release branch with no newsfragments, all good.") | Running it on a release branch returns green if there is no
newsfragments even if there are changes. | test_release | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_releaseWithNewsfragments(self):
"""
Running it on a release branch returns red if there are new
newsfragments.
"""
runCommand(["git", "checkout", "-b", "release-16.11111-9001"],
cwd=self.repo.path)
newsfragments = self.repo.child("twisted").child("newsfragments")
newsfragments.makedirs()
fragment = newsfragments.child("1234.misc")
fragment.setContent(b"")
unrelated = self.repo.child("somefile")
unrelated.setContent(b"Boo")
runCommand(["git", "add", fragment.path, unrelated.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "fragment"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (1,))
self.assertEqual(logs[-1],
"No newsfragments should be on the release branch.") | Running it on a release branch returns red if there are new
newsfragments. | test_releaseWithNewsfragments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_onlyQuotes(self):
"""
Running it on a branch with only a quotefile change gives green.
"""
runCommand(["git", "checkout", "-b", "quotefile"],
cwd=self.repo.path)
fun = self.repo.child("docs").child("fun")
fun.makedirs()
quotes = fun.child("Twisted.Quotes")
quotes.setContent(b"Beep boop")
runCommand(["git", "add", quotes.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "quotes"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(logs[-1],
"Quotes change only; no newsfragment needed.") | Running it on a branch with only a quotefile change gives green. | test_onlyQuotes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_newsfragmentAdded(self):
"""
Running it on a branch with a fragment in the newsfragments dir added
returns green.
"""
runCommand(["git", "checkout", "-b", "quotefile"],
cwd=self.repo.path)
newsfragments = self.repo.child("twisted").child("newsfragments")
newsfragments.makedirs()
fragment = newsfragments.child("1234.misc")
fragment.setContent(b"")
unrelated = self.repo.child("somefile")
unrelated.setContent(b"Boo")
runCommand(["git", "add", fragment.path, unrelated.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "newsfragment"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(logs[-1], "Found twisted/newsfragments/1234.misc") | Running it on a branch with a fragment in the newsfragments dir added
returns green. | test_newsfragmentAdded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_topfileButNotFragmentAdded(self):
"""
Running it on a branch with a non-fragment in the topfiles dir does not
return green.
"""
runCommand(["git", "checkout", "-b", "quotefile"],
cwd=self.repo.path)
topfiles = self.repo.child("twisted").child("topfiles")
topfiles.makedirs()
notFragment = topfiles.child("1234.txt")
notFragment.setContent(b"")
unrelated = self.repo.child("somefile")
unrelated.setContent(b"Boo")
runCommand(["git", "add", notFragment.path, unrelated.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "not topfile"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (1,))
self.assertEqual(logs[-1],
"No newsfragment found. Have you committed it?") | Running it on a branch with a non-fragment in the topfiles dir does not
return green. | test_topfileButNotFragmentAdded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def test_newsfragmentAddedButWithOtherNewsfragments(self):
"""
Running it on a branch with a fragment in the topfiles dir added
returns green, even if there are other files in the topfiles dir.
"""
runCommand(["git", "checkout", "-b", "quotefile"],
cwd=self.repo.path)
newsfragments = self.repo.child("twisted").child("newsfragments")
newsfragments.makedirs()
fragment = newsfragments.child("1234.misc")
fragment.setContent(b"")
unrelated = newsfragments.child("somefile")
unrelated.setContent(b"Boo")
runCommand(["git", "add", fragment.path, unrelated.path],
cwd=self.repo.path)
runCommand(["git", "commit", "-m", "newsfragment"],
cwd=self.repo.path)
logs = []
with self.assertRaises(SystemExit) as e:
CheckNewsfragmentScript(logs.append).main([self.repo.path])
self.assertEqual(e.exception.args, (0,))
self.assertEqual(logs[-1], "Found twisted/newsfragments/1234.misc") | Running it on a branch with a fragment in the topfiles dir added
returns green, even if there are other files in the topfiles dir. | test_newsfragmentAddedButWithOtherNewsfragments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py | MIT |
def assertUnicoded(self, u):
"""
The given L{URL}'s components should be L{unicode}.
@param u: The L{URL} to test.
"""
self.assertTrue(isinstance(u.scheme, unicode)
or u.scheme is None, repr(u))
self.assertTrue(isinstance(u.host, unicode)
or u.host is None, repr(u))
for seg in u.path:
self.assertIsInstance(seg, unicode, repr(u))
for (k, v) in u.query:
self.assertIsInstance(k, unicode, repr(u))
self.assertTrue(v is None or isinstance(v, unicode), repr(u))
self.assertIsInstance(u.fragment, unicode, repr(u)) | The given L{URL}'s components should be L{unicode}.
@param u: The L{URL} to test. | assertUnicoded | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def assertURL(self, u, scheme, host, path, query,
fragment, port, userinfo=u''):
"""
The given L{URL} should have the given components.
@param u: The actual L{URL} to examine.
@param scheme: The expected scheme.
@param host: The expected host.
@param path: The expected path.
@param query: The expected query.
@param fragment: The expected fragment.
@param port: The expected port.
@param userinfo: The expected userinfo.
"""
actual = (u.scheme, u.host, u.path, u.query,
u.fragment, u.port, u.userinfo)
expected = (scheme, host, tuple(path), tuple(query),
fragment, port, u.userinfo)
self.assertEqual(actual, expected) | The given L{URL} should have the given components.
@param u: The actual L{URL} to examine.
@param scheme: The expected scheme.
@param host: The expected host.
@param path: The expected path.
@param query: The expected query.
@param fragment: The expected fragment.
@param port: The expected port.
@param userinfo: The expected userinfo. | assertURL | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_initDefaults(self):
"""
L{URL} should have appropriate default values.
"""
def check(u):
self.assertUnicoded(u)
self.assertURL(u, u'http', u'', [], [], u'', 80, u'')
check(URL(u'http', u''))
check(URL(u'http', u'', [], []))
check(URL(u'http', u'', [], [], u'')) | L{URL} should have appropriate default values. | test_initDefaults | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_init(self):
"""
L{URL} should accept L{unicode} parameters.
"""
u = URL(u's', u'h', [u'p'], [(u'k', u'v'), (u'k', None)], u'f')
self.assertUnicoded(u)
self.assertURL(u, u's', u'h', [u'p'], [(u'k', u'v'), (u'k', None)],
u'f', None)
self.assertURL(URL(u'http', u'\xe0', [u'\xe9'],
[(u'\u03bb', u'\u03c0')], u'\u22a5'),
u'http', u'\xe0', [u'\xe9'],
[(u'\u03bb', u'\u03c0')], u'\u22a5', 80) | L{URL} should accept L{unicode} parameters. | test_init | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_initPercent(self):
"""
L{URL} should accept (and not interpret) percent characters.
"""
u = URL(u's', u'%68', [u'%70'], [(u'%6B', u'%76'), (u'%6B', None)],
u'%66')
self.assertUnicoded(u)
self.assertURL(u,
u's', u'%68', [u'%70'],
[(u'%6B', u'%76'), (u'%6B', None)],
u'%66', None) | L{URL} should accept (and not interpret) percent characters. | test_initPercent | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_repr(self):
"""
L{URL.__repr__} will display the canonical form of the URL, wrapped in
a L{URL.fromText} invocation, so that it is C{eval}-able but still easy
to read.
"""
self.assertEqual(
repr(URL(scheme=u'http', host=u'foo', path=[u'bar'],
query=[(u'baz', None), (u'k', u'v')],
fragment=u'frob')),
"URL.from_text(%s)" % (repr(u"http://foo/bar?baz&k=v#frob"),)
) | L{URL.__repr__} will display the canonical form of the URL, wrapped in
a L{URL.fromText} invocation, so that it is C{eval}-able but still easy
to read. | test_repr | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_fromText(self):
"""
Round-tripping L{URL.fromText} with C{str} results in an equivalent
URL.
"""
urlpath = URL.fromText(theurl)
self.assertEqual(theurl, urlpath.asText()) | Round-tripping L{URL.fromText} with C{str} results in an equivalent
URL. | test_fromText | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_roundtrip(self):
"""
L{URL.asText} should invert L{URL.fromText}.
"""
tests = (
"http://localhost",
"http://localhost/",
"http://localhost/foo",
"http://localhost/foo/",
"http://localhost/foo!!bar/",
"http://localhost/foo%20bar/",
"http://localhost/foo%2Fbar/",
"http://localhost/foo?n",
"http://localhost/foo?n=v",
"http://localhost/foo?n=/a/b",
"http://example.com/foo!@$bar?b!@z=123",
"http://localhost/asd?a=asd%20sdf/345",
"http://(%2525)/(%2525)?(%2525)&(%2525)=(%2525)#(%2525)",
"http://(%C3%A9)/(%C3%A9)?(%C3%A9)&(%C3%A9)=(%C3%A9)#(%C3%A9)",
)
for test in tests:
result = URL.fromText(test).asText()
self.assertEqual(test, result) | L{URL.asText} should invert L{URL.fromText}. | test_roundtrip | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_equality(self):
"""
Two URLs decoded using L{URL.fromText} will be equal (C{==}) if they
decoded same URL string, and unequal (C{!=}) if they decoded different
strings.
"""
urlpath = URL.fromText(theurl)
self.assertEqual(urlpath, URL.fromText(theurl))
self.assertNotEqual(
urlpath,
URL.fromText('ftp://www.anotherinvaliddomain.com/'
'foo/bar/baz/?zot=21&zut')
) | Two URLs decoded using L{URL.fromText} will be equal (C{==}) if they
decoded same URL string, and unequal (C{!=}) if they decoded different
strings. | test_equality | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_fragmentEquality(self):
"""
An URL created with the empty string for a fragment compares equal
to an URL created with an unspecified fragment.
"""
self.assertEqual(URL(fragment=u''), URL())
self.assertEqual(URL.fromText(u"http://localhost/#"),
URL.fromText(u"http://localhost/")) | An URL created with the empty string for a fragment compares equal
to an URL created with an unspecified fragment. | test_fragmentEquality | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_child(self):
"""
L{URL.child} appends a new path segment, but does not affect the query
or fragment.
"""
urlpath = URL.fromText(theurl)
self.assertEqual("http://www.foo.com/a/nice/path/gong?zot=23&zut",
urlpath.child(u'gong').asText())
self.assertEqual("http://www.foo.com/a/nice/path/gong%2F?zot=23&zut",
urlpath.child(u'gong/').asText())
self.assertEqual(
"http://www.foo.com/a/nice/path/gong%2Fdouble?zot=23&zut",
urlpath.child(u'gong/double').asText()
)
self.assertEqual(
"http://www.foo.com/a/nice/path/gong%2Fdouble%2F?zot=23&zut",
urlpath.child(u'gong/double/').asText()
) | L{URL.child} appends a new path segment, but does not affect the query
or fragment. | test_child | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_multiChild(self):
"""
L{URL.child} receives multiple segments as C{*args} and appends each in
turn.
"""
self.assertEqual(URL.fromText('http://example.com/a/b')
.child('c', 'd', 'e').asText(),
'http://example.com/a/b/c/d/e') | L{URL.child} receives multiple segments as C{*args} and appends each in
turn. | test_multiChild | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_childInitRoot(self):
"""
L{URL.child} of a L{URL} without a path produces a L{URL} with a single
path segment.
"""
childURL = URL(host=u"www.foo.com").child(u"c")
self.assertTrue(childURL.rooted)
self.assertEqual("http://www.foo.com/c", childURL.asText()) | L{URL.child} of a L{URL} without a path produces a L{URL} with a single
path segment. | test_childInitRoot | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_sibling(self):
"""
L{URL.sibling} of a L{URL} replaces the last path segment, but does not
affect the query or fragment.
"""
urlpath = URL.fromText(theurl)
self.assertEqual(
"http://www.foo.com/a/nice/path/sister?zot=23&zut",
urlpath.sibling(u'sister').asText()
)
# Use an url without trailing '/' to check child removal.
theurl2 = "http://www.foo.com/a/nice/path?zot=23&zut"
urlpath = URL.fromText(theurl2)
self.assertEqual(
"http://www.foo.com/a/nice/sister?zot=23&zut",
urlpath.sibling(u'sister').asText()
) | L{URL.sibling} of a L{URL} replaces the last path segment, but does not
affect the query or fragment. | test_sibling | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_click(self):
"""
L{URL.click} interprets the given string as a relative URI-reference
and returns a new L{URL} interpreting C{self} as the base absolute URI.
"""
urlpath = URL.fromText(theurl)
# A null uri should be valid (return here).
self.assertEqual("http://www.foo.com/a/nice/path/?zot=23&zut",
urlpath.click("").asText())
# A simple relative path remove the query.
self.assertEqual("http://www.foo.com/a/nice/path/click",
urlpath.click("click").asText())
# An absolute path replace path and query.
self.assertEqual("http://www.foo.com/click",
urlpath.click("/click").asText())
# Replace just the query.
self.assertEqual("http://www.foo.com/a/nice/path/?burp",
urlpath.click("?burp").asText())
# One full url to another should not generate '//' between authority.
# and path
self.assertNotIn("//foobar",
urlpath.click('http://www.foo.com/foobar').asText())
# From a url with no query clicking a url with a query, the query
# should be handled properly.
u = URL.fromText('http://www.foo.com/me/noquery')
self.assertEqual('http://www.foo.com/me/17?spam=158',
u.click('/me/17?spam=158').asText())
# Check that everything from the path onward is removed when the click
# link has no path.
u = URL.fromText('http://localhost/foo?abc=def')
self.assertEqual(u.click('http://www.python.org').asText(),
'http://www.python.org') | L{URL.click} interprets the given string as a relative URI-reference
and returns a new L{URL} interpreting C{self} as the base absolute URI. | test_click | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_clickRFC3986(self):
"""
L{URL.click} should correctly resolve the examples in RFC 3986.
"""
base = URL.fromText(relativeLinkBaseForRFC3986)
for (ref, expected) in relativeLinkTestsForRFC3986:
self.assertEqual(base.click(ref).asText(), expected) | L{URL.click} should correctly resolve the examples in RFC 3986. | test_clickRFC3986 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_clickSchemeRelPath(self):
"""
L{URL.click} should not accept schemes with relative paths.
"""
base = URL.fromText(relativeLinkBaseForRFC3986)
self.assertRaises(NotImplementedError, base.click, 'g:h')
self.assertRaises(NotImplementedError, base.click, 'http:h') | L{URL.click} should not accept schemes with relative paths. | test_clickSchemeRelPath | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_cloneUnchanged(self):
"""
Verify that L{URL.replace} doesn't change any of the arguments it
is passed.
"""
urlpath = URL.fromText('https://x:1/y?z=1#A')
self.assertEqual(
urlpath.replace(urlpath.scheme,
urlpath.host,
urlpath.path,
urlpath.query,
urlpath.fragment,
urlpath.port),
urlpath)
self.assertEqual(
urlpath.replace(),
urlpath) | Verify that L{URL.replace} doesn't change any of the arguments it
is passed. | test_cloneUnchanged | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_clickCollapse(self):
"""
L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
5.2.4.
"""
tests = [
['http://localhost/', '.', 'http://localhost/'],
['http://localhost/', '..', 'http://localhost/'],
['http://localhost/a/b/c', '.', 'http://localhost/a/b/'],
['http://localhost/a/b/c', '..', 'http://localhost/a/'],
['http://localhost/a/b/c', './d/e', 'http://localhost/a/b/d/e'],
['http://localhost/a/b/c', '../d/e', 'http://localhost/a/d/e'],
['http://localhost/a/b/c', '/./d/e', 'http://localhost/d/e'],
['http://localhost/a/b/c', '/../d/e', 'http://localhost/d/e'],
['http://localhost/a/b/c/', '../../d/e/',
'http://localhost/a/d/e/'],
['http://localhost/a/./c', '../d/e', 'http://localhost/d/e'],
['http://localhost/a/./c/', '../d/e', 'http://localhost/a/d/e'],
['http://localhost/a/b/c/d', './e/../f/../g',
'http://localhost/a/b/c/g'],
['http://localhost/a/b/c', 'd//e', 'http://localhost/a/b/d//e'],
]
for start, click, expected in tests:
actual = URL.fromText(start).click(click).asText()
self.assertEqual(
actual,
expected,
"{start}.click({click}) => {actual} not {expected}".format(
start=start,
click=repr(click),
actual=actual,
expected=expected,
)
) | L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
5.2.4. | test_clickCollapse | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_queryAdd(self):
"""
L{URL.add} adds query parameters.
"""
self.assertEqual(
"http://www.foo.com/a/nice/path/?foo=bar",
URL.fromText("http://www.foo.com/a/nice/path/")
.add(u"foo", u"bar").asText())
self.assertEqual(
"http://www.foo.com/?foo=bar",
URL(host=u"www.foo.com").add(u"foo", u"bar")
.asText())
urlpath = URL.fromText(theurl)
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=23&zut&burp",
urlpath.add(u"burp").asText())
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx",
urlpath.add(u"burp", u"xxx").asText())
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zing",
urlpath.add(u"burp", u"xxx").add(u"zing").asText())
# Note the inversion!
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=23&zut&zing&burp=xxx",
urlpath.add(u"zing").add(u"burp", u"xxx").asText())
# Note the two values for the same name.
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zot=32",
urlpath.add(u"burp", u"xxx").add(u"zot", u'32')
.asText()) | L{URL.add} adds query parameters. | test_queryAdd | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_querySet(self):
"""
L{URL.set} replaces query parameters by name.
"""
urlpath = URL.fromText(theurl)
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=32&zut",
urlpath.set(u"zot", u'32').asText())
# Replace name without value with name/value and vice-versa.
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot&zut=itworked",
urlpath.set(u"zot").set(u"zut", u"itworked").asText()
)
# Q: what happens when the query has two values and we replace?
# A: we replace both values with a single one
self.assertEqual(
"http://www.foo.com/a/nice/path/?zot=32&zut",
urlpath.add(u"zot", u"xxx").set(u"zot", u'32').asText()
) | L{URL.set} replaces query parameters by name. | test_querySet | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_queryRemove(self):
"""
L{URL.remove} removes all instances of a query parameter.
"""
url = URL.fromText(u"https://example.com/a/b/?foo=1&bar=2&foo=3")
self.assertEqual(
url.remove(u"foo"),
URL.fromText(u"https://example.com/a/b/?bar=2")
) | L{URL.remove} removes all instances of a query parameter. | test_queryRemove | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_empty(self):
"""
An empty L{URL} should serialize as the empty string.
"""
self.assertEqual(URL().asText(), u'') | An empty L{URL} should serialize as the empty string. | test_empty | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_justQueryText(self):
"""
An L{URL} with query text should serialize as just query text.
"""
u = URL(query=[(u"hello", u"world")])
self.assertEqual(u.asText(), u'?hello=world') | An L{URL} with query text should serialize as just query text. | test_justQueryText | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_identicalEqual(self):
"""
L{URL} compares equal to itself.
"""
u = URL.fromText('http://localhost/')
self.assertEqual(u, u) | L{URL} compares equal to itself. | test_identicalEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_similarEqual(self):
"""
URLs with equivalent components should compare equal.
"""
u1 = URL.fromText('http://localhost/')
u2 = URL.fromText('http://localhost/')
self.assertEqual(u1, u2) | URLs with equivalent components should compare equal. | test_similarEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_differentNotEqual(self):
"""
L{URL}s that refer to different resources are both unequal (C{!=}) and
also not equal (not C{==}).
"""
u1 = URL.fromText('http://localhost/a')
u2 = URL.fromText('http://localhost/b')
self.assertFalse(u1 == u2, "%r != %r" % (u1, u2))
self.assertNotEqual(u1, u2) | L{URL}s that refer to different resources are both unequal (C{!=}) and
also not equal (not C{==}). | test_differentNotEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_otherTypesNotEqual(self):
"""
L{URL} is not equal (C{==}) to other types.
"""
u = URL.fromText('http://localhost/')
self.assertFalse(u == 42, "URL must not equal a number.")
self.assertFalse(u == object(), "URL must not equal an object.")
self.assertNotEqual(u, 42)
self.assertNotEqual(u, object()) | L{URL} is not equal (C{==}) to other types. | test_otherTypesNotEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_identicalNotUnequal(self):
"""
Identical L{URL}s are not unequal (C{!=}) to each other.
"""
u = URL.fromText('http://localhost/')
self.assertFalse(u != u, "%r == itself" % u) | Identical L{URL}s are not unequal (C{!=}) to each other. | test_identicalNotUnequal | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_similarNotUnequal(self):
"""
Structurally similar L{URL}s are not unequal (C{!=}) to each other.
"""
u1 = URL.fromText('http://localhost/')
u2 = URL.fromText('http://localhost/')
self.assertFalse(u1 != u2, "%r == %r" % (u1, u2)) | Structurally similar L{URL}s are not unequal (C{!=}) to each other. | test_similarNotUnequal | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_differentUnequal(self):
"""
Structurally different L{URL}s are unequal (C{!=}) to each other.
"""
u1 = URL.fromText('http://localhost/a')
u2 = URL.fromText('http://localhost/b')
self.assertTrue(u1 != u2, "%r == %r" % (u1, u2)) | Structurally different L{URL}s are unequal (C{!=}) to each other. | test_differentUnequal | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_otherTypesUnequal(self):
"""
L{URL} is unequal (C{!=}) to other types.
"""
u = URL.fromText('http://localhost/')
self.assertTrue(u != 42, "URL must differ from a number.")
self.assertTrue(u != object(), "URL must be differ from an object.") | L{URL} is unequal (C{!=}) to other types. | test_otherTypesUnequal | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_asURI(self):
"""
L{URL.asURI} produces an URI which converts any URI unicode encoding
into pure US-ASCII and returns a new L{URL}.
"""
unicodey = ('http://\N{LATIN SMALL LETTER E WITH ACUTE}.com/'
'\N{LATIN SMALL LETTER E}\N{COMBINING ACUTE ACCENT}'
'?\N{LATIN SMALL LETTER A}\N{COMBINING ACUTE ACCENT}='
'\N{LATIN SMALL LETTER I}\N{COMBINING ACUTE ACCENT}'
'#\N{LATIN SMALL LETTER U}\N{COMBINING ACUTE ACCENT}')
iri = URL.fromText(unicodey)
uri = iri.asURI()
self.assertEqual(iri.host, '\N{LATIN SMALL LETTER E WITH ACUTE}.com')
self.assertEqual(iri.path[0],
'\N{LATIN SMALL LETTER E}\N{COMBINING ACUTE ACCENT}')
self.assertEqual(iri.asText(), unicodey)
expectedURI = 'http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BA'
actualURI = uri.asText()
self.assertEqual(actualURI, expectedURI,
'%r != %r' % (actualURI, expectedURI)) | L{URL.asURI} produces an URI which converts any URI unicode encoding
into pure US-ASCII and returns a new L{URL}. | test_asURI | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_asIRI(self):
"""
L{URL.asIRI} decodes any percent-encoded text in the URI, making it
more suitable for reading by humans, and returns a new L{URL}.
"""
asciiish = 'http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BA'
uri = URL.fromText(asciiish)
iri = uri.asIRI()
self.assertEqual(uri.host, 'xn--9ca.com')
self.assertEqual(uri.path[0], '%C3%A9')
self.assertEqual(uri.asText(), asciiish)
expectedIRI = ('http://\N{LATIN SMALL LETTER E WITH ACUTE}.com/'
'\N{LATIN SMALL LETTER E WITH ACUTE}'
'?\N{LATIN SMALL LETTER A WITH ACUTE}='
'\N{LATIN SMALL LETTER I WITH ACUTE}'
'#\N{LATIN SMALL LETTER U WITH ACUTE}')
actualIRI = iri.asText()
self.assertEqual(actualIRI, expectedIRI,
'%r != %r' % (actualIRI, expectedIRI)) | L{URL.asIRI} decodes any percent-encoded text in the URI, making it
more suitable for reading by humans, and returns a new L{URL}. | test_asIRI | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_badUTF8AsIRI(self):
"""
Bad UTF-8 in a path segment, query parameter, or fragment results in
that portion of the URI remaining percent-encoded in the IRI.
"""
urlWithBinary = 'http://xn--9ca.com/%00%FF/%C3%A9'
uri = URL.fromText(urlWithBinary)
iri = uri.asIRI()
expectedIRI = ('http://\N{LATIN SMALL LETTER E WITH ACUTE}.com/'
'%00%FF/'
'\N{LATIN SMALL LETTER E WITH ACUTE}')
actualIRI = iri.asText()
self.assertEqual(actualIRI, expectedIRI,
'%r != %r' % (actualIRI, expectedIRI)) | Bad UTF-8 in a path segment, query parameter, or fragment results in
that portion of the URI remaining percent-encoded in the IRI. | test_badUTF8AsIRI | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_alreadyIRIAsIRI(self):
"""
A L{URL} composed of non-ASCII text will result in non-ASCII text.
"""
unicodey = ('http://\N{LATIN SMALL LETTER E WITH ACUTE}.com/'
'\N{LATIN SMALL LETTER E}\N{COMBINING ACUTE ACCENT}'
'?\N{LATIN SMALL LETTER A}\N{COMBINING ACUTE ACCENT}='
'\N{LATIN SMALL LETTER I}\N{COMBINING ACUTE ACCENT}'
'#\N{LATIN SMALL LETTER U}\N{COMBINING ACUTE ACCENT}')
iri = URL.fromText(unicodey)
alsoIRI = iri.asIRI()
self.assertEqual(alsoIRI.asText(), unicodey) | A L{URL} composed of non-ASCII text will result in non-ASCII text. | test_alreadyIRIAsIRI | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_alreadyURIAsURI(self):
"""
A L{URL} composed of encoded text will remain encoded.
"""
expectedURI = 'http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BA'
uri = URL.fromText(expectedURI)
actualURI = uri.asURI().asText()
self.assertEqual(actualURI, expectedURI) | A L{URL} composed of encoded text will remain encoded. | test_alreadyURIAsURI | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_userinfo(self):
"""
L{URL.fromText} will parse the C{userinfo} portion of the URI
separately from the host and port.
"""
url = URL.fromText(
'http://someuser:[email protected]/some-segment@ignore'
)
self.assertEqual(url.authority(True),
'someuser:[email protected]')
self.assertEqual(url.authority(False), 'someuser:@example.com')
self.assertEqual(url.userinfo, 'someuser:somepassword')
self.assertEqual(url.user, 'someuser')
self.assertEqual(url.asText(),
'http://someuser:@example.com/some-segment@ignore')
self.assertEqual(
url.replace(userinfo=u"someuser").asText(),
'http://[email protected]/some-segment@ignore'
) | L{URL.fromText} will parse the C{userinfo} portion of the URI
separately from the host and port. | test_userinfo | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_portText(self):
"""
L{URL.fromText} parses custom port numbers as integers.
"""
portURL = URL.fromText(u"http://www.example.com:8080/")
self.assertEqual(portURL.port, 8080)
self.assertEqual(portURL.asText(), u"http://www.example.com:8080/") | L{URL.fromText} parses custom port numbers as integers. | test_portText | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_mailto(self):
"""
Although L{URL} instances are mainly for dealing with HTTP, other
schemes (such as C{mailto:}) should work as well. For example,
L{URL.fromText}/L{URL.asText} round-trips cleanly for a C{mailto:} URL
representing an email address.
"""
self.assertEqual(URL.fromText(u"mailto:[email protected]").asText(),
u"mailto:[email protected]") | Although L{URL} instances are mainly for dealing with HTTP, other
schemes (such as C{mailto:}) should work as well. For example,
L{URL.fromText}/L{URL.asText} round-trips cleanly for a C{mailto:} URL
representing an email address. | test_mailto | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_queryIterable(self):
"""
When a L{URL} is created with a C{query} argument, the C{query}
argument is converted into an N-tuple of 2-tuples.
"""
url = URL(query=[[u'alpha', u'beta']])
self.assertEqual(url.query, ((u'alpha', u'beta'),)) | When a L{URL} is created with a C{query} argument, the C{query}
argument is converted into an N-tuple of 2-tuples. | test_queryIterable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_pathIterable(self):
"""
When a L{URL} is created with a C{path} argument, the C{path} is
converted into a tuple.
"""
url = URL(path=[u'hello', u'world'])
self.assertEqual(url.path, (u'hello', u'world')) | When a L{URL} is created with a C{path} argument, the C{path} is
converted into a tuple. | test_pathIterable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_invalidArguments(self):
"""
Passing an argument of the wrong type to any of the constructor
arguments of L{URL} will raise a descriptive L{TypeError}.
L{URL} typechecks very aggressively to ensure that its constitutent
parts are all properly immutable and to prevent confusing errors when
bad data crops up in a method call long after the code that called the
constructor is off the stack.
"""
class Unexpected(object):
def __str__(self):
return "wrong"
def __repr__(self):
return "<unexpected>"
defaultExpectation = "unicode" if bytes is str else "str"
def assertRaised(raised, expectation, name):
self.assertEqual(str(raised.exception),
"expected {} for {}, got {}".format(
expectation,
name, "<unexpected>"))
def check(param, expectation=defaultExpectation):
with self.assertRaises(TypeError) as raised:
URL(**{param: Unexpected()})
assertRaised(raised, expectation, param)
check("scheme")
check("host")
check("fragment")
check("rooted", "bool")
check("userinfo")
check("port", "int or NoneType")
with self.assertRaises(TypeError) as raised:
URL(path=[Unexpected(),])
assertRaised(raised, defaultExpectation, "path segment")
with self.assertRaises(TypeError) as raised:
URL(query=[(u"name", Unexpected()),])
assertRaised(raised, defaultExpectation + " or NoneType",
"query parameter value")
with self.assertRaises(TypeError) as raised:
URL(query=[(Unexpected(), u"value"),])
assertRaised(raised, defaultExpectation, "query parameter name")
# No custom error message for this one, just want to make sure
# non-2-tuples don't get through.
with self.assertRaises(TypeError):
URL(query=[Unexpected()])
with self.assertRaises(ValueError):
URL(query=[(u'k', u'v', u'vv')])
with self.assertRaises(ValueError):
URL(query=[(u'k',)])
url = URL.fromText("https://valid.example.com/")
with self.assertRaises(TypeError) as raised:
url.child(Unexpected())
assertRaised(raised, defaultExpectation, "path segment")
with self.assertRaises(TypeError) as raised:
url.sibling(Unexpected())
assertRaised(raised, defaultExpectation, "path segment")
with self.assertRaises(TypeError) as raised:
url.click(Unexpected())
assertRaised(raised, defaultExpectation, "relative URL") | Passing an argument of the wrong type to any of the constructor
arguments of L{URL} will raise a descriptive L{TypeError}.
L{URL} typechecks very aggressively to ensure that its constitutent
parts are all properly immutable and to prevent confusing errors when
bad data crops up in a method call long after the code that called the
constructor is off the stack. | test_invalidArguments | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_technicallyTextIsIterableBut(self):
"""
Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
C{URL(path="foo")} resulting in C{URL.fromText("f/o/o")} is never what
you want.
"""
with self.assertRaises(TypeError) as raised:
URL(path=u'foo')
self.assertEqual(
str(raised.exception),
"expected iterable of text for path, not: {}"
.format(repr(u'foo'))
) | Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
C{URL(path="foo")} resulting in C{URL.fromText("f/o/o")} is never what
you want. | test_technicallyTextIsIterableBut | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_urlDeprecation(self):
"""
L{twisted.python.url} is deprecated since Twisted 17.5.0.
"""
from twisted.python import url
url
warningsShown = self.flushWarnings([self.test_urlDeprecation])
self.assertEqual(1, len(warningsShown))
self.assertEqual(
("twisted.python.url was deprecated in Twisted 17.5.0:"
" Please use hyperlink from PyPI instead."),
warningsShown[0]['message']) | L{twisted.python.url} is deprecated since Twisted 17.5.0. | test_urlDeprecation | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_url.py | MIT |
def test_inheritedDescriptors(self):
"""
C{inheritedDescriptors} returns a list of integers giving the file
descriptors which were inherited from systemd.
"""
sddaemon = self.getDaemon(7, 3)
self.assertEqual([7, 8, 9], sddaemon.inheritedDescriptors()) | C{inheritedDescriptors} returns a list of integers giving the file
descriptors which were inherited from systemd. | test_inheritedDescriptors | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_repeated(self):
"""
Any subsequent calls to C{inheritedDescriptors} return the same list.
"""
sddaemon = self.getDaemon(7, 3)
self.assertEqual(
sddaemon.inheritedDescriptors(),
sddaemon.inheritedDescriptors()) | Any subsequent calls to C{inheritedDescriptors} return the same list. | test_repeated | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def getDaemon(self, start, count):
"""
Invent C{count} new I{file descriptors} (actually integers, attached to
no real file description), starting at C{start}. Construct and return a
new L{ListenFDs} which will claim those integers represent inherited
file descriptors.
"""
return ListenFDs(range(start, start + count)) | Invent C{count} new I{file descriptors} (actually integers, attached to
no real file description), starting at C{start}. Construct and return a
new L{ListenFDs} which will claim those integers represent inherited
file descriptors. | getDaemon | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def initializeEnvironment(self, count, pid):
"""
Create a copy of the process environment and add I{LISTEN_FDS} and
I{LISTEN_PID} (the environment variables set by systemd) to it.
"""
result = os.environ.copy()
result['LISTEN_FDS'] = str(count)
result['LISTEN_PID'] = str(pid)
return result | Create a copy of the process environment and add I{LISTEN_FDS} and
I{LISTEN_PID} (the environment variables set by systemd) to it. | initializeEnvironment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def getDaemon(self, start, count):
"""
Create a new L{ListenFDs} instance, initialized with a fake environment
dictionary which will be set up as systemd would have set it up if
C{count} descriptors were being inherited. The descriptors will also
start at C{start}.
"""
fakeEnvironment = self.initializeEnvironment(count, os.getpid())
return ListenFDs.fromEnvironment(environ=fakeEnvironment, start=start) | Create a new L{ListenFDs} instance, initialized with a fake environment
dictionary which will be set up as systemd would have set it up if
C{count} descriptors were being inherited. The descriptors will also
start at C{start}. | getDaemon | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_secondEnvironment(self):
"""
Only a single L{Environment} can extract inherited file descriptors.
"""
fakeEnvironment = self.initializeEnvironment(3, os.getpid())
first = ListenFDs.fromEnvironment(environ=fakeEnvironment)
second = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual(list(range(3, 6)), first.inheritedDescriptors())
self.assertEqual([], second.inheritedDescriptors()) | Only a single L{Environment} can extract inherited file descriptors. | test_secondEnvironment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_mismatchedPID(self):
"""
If the current process PID does not match the PID in the environment, no
inherited descriptors are reported.
"""
fakeEnvironment = self.initializeEnvironment(3, os.getpid() + 1)
sddaemon = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual([], sddaemon.inheritedDescriptors()) | If the current process PID does not match the PID in the environment, no
inherited descriptors are reported. | test_mismatchedPID | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_missingPIDVariable(self):
"""
If the I{LISTEN_PID} environment variable is not present, no inherited
descriptors are reported.
"""
fakeEnvironment = self.initializeEnvironment(3, os.getpid())
del fakeEnvironment['LISTEN_PID']
sddaemon = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual([], sddaemon.inheritedDescriptors()) | If the I{LISTEN_PID} environment variable is not present, no inherited
descriptors are reported. | test_missingPIDVariable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_nonIntegerPIDVariable(self):
"""
If the I{LISTEN_PID} environment variable is set to a string that cannot
be parsed as an integer, no inherited descriptors are reported.
"""
fakeEnvironment = self.initializeEnvironment(3, "hello, world")
sddaemon = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual([], sddaemon.inheritedDescriptors()) | If the I{LISTEN_PID} environment variable is set to a string that cannot
be parsed as an integer, no inherited descriptors are reported. | test_nonIntegerPIDVariable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_missingFDSVariable(self):
"""
If the I{LISTEN_FDS} environment variable is not present, no inherited
descriptors are reported.
"""
fakeEnvironment = self.initializeEnvironment(3, os.getpid())
del fakeEnvironment['LISTEN_FDS']
sddaemon = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual([], sddaemon.inheritedDescriptors()) | If the I{LISTEN_FDS} environment variable is not present, no inherited
descriptors are reported. | test_missingFDSVariable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_nonIntegerFDSVariable(self):
"""
If the I{LISTEN_FDS} environment variable is set to a string that cannot
be parsed as an integer, no inherited descriptors are reported.
"""
fakeEnvironment = self.initializeEnvironment("hello, world", os.getpid())
sddaemon = ListenFDs.fromEnvironment(environ=fakeEnvironment)
self.assertEqual([], sddaemon.inheritedDescriptors()) | If the I{LISTEN_FDS} environment variable is set to a string that cannot
be parsed as an integer, no inherited descriptors are reported. | test_nonIntegerFDSVariable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
def test_defaultEnviron(self):
"""
If the process environment is not explicitly passed to
L{Environment.__init__}, the real process environment dictionary is
used.
"""
self.patch(os, 'environ', {
'LISTEN_PID': str(os.getpid()),
'LISTEN_FDS': '5'})
sddaemon = ListenFDs.fromEnvironment()
self.assertEqual(list(range(3, 3 + 5)),
sddaemon.inheritedDescriptors()) | If the process environment is not explicitly passed to
L{Environment.__init__}, the real process environment dictionary is
used. | test_defaultEnviron | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_systemd.py | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.