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
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def assertSamePath(self, first, second):
"""
Assert that the two paths are the same, considering case normalization
appropriate for the current platform.
@type first: L{FilePath}
@type second: L{FilePath}
@raise C{self.failureType}: If the paths are not the same.
"""
self.assertTrue(
normcase(first.path) == normcase(second.path),
"%r != %r" % (first, second)) | Assert that the two paths are the same, considering case normalization
appropriate for the current platform.
@type first: L{FilePath}
@type second: L{FilePath}
@raise C{self.failureType}: If the paths are not the same. | assertSamePath | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_renamedFile(self):
"""
Even if the implementation of a deprecated function is moved around on
the filesystem, the line number in the warning emitted by
L{deprecate.warnAboutFunction} points to a line in the implementation of
the deprecated function.
"""
from twisted_private_helper import module
# Clean up the state resulting from that import; we're not going to use
# this module, so it should go away.
del sys.modules['twisted_private_helper']
del sys.modules[module.__name__]
# Rename the source directory
self.package.moveTo(self.package.sibling(b'twisted_renamed_helper'))
# Make sure importlib notices we've changed importable packages:
if invalidate_caches:
invalidate_caches()
# Import the newly renamed version
from twisted_renamed_helper import module
self.addCleanup(sys.modules.pop, 'twisted_renamed_helper')
self.addCleanup(sys.modules.pop, module.__name__)
module.callTestFunction()
warningsShown = self.flushWarnings([module.testFunction])
warnedPath = FilePath(warningsShown[0]["filename"].encode("utf-8"))
expectedPath = self.package.sibling(
b'twisted_renamed_helper').child(b'module.py')
self.assertSamePath(warnedPath, expectedPath)
self.assertEqual(warningsShown[0]["lineno"], 9)
self.assertEqual(warningsShown[0]["message"], "A Warning String")
self.assertEqual(len(warningsShown), 1) | Even if the implementation of a deprecated function is moved around on
the filesystem, the line number in the warning emitted by
L{deprecate.warnAboutFunction} points to a line in the implementation of
the deprecated function. | test_renamedFile | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_filteredWarning(self):
"""
L{deprecate.warnAboutFunction} emits a warning that will be filtered if
L{warnings.filterwarning} is called with the module name of the
deprecated function.
"""
# Clean up anything *else* that might spuriously filter out the warning,
# such as the "always" simplefilter set up by unittest._collectWarnings.
# We'll also rely on trial to restore the original filters afterwards.
del warnings.filters[:]
warnings.filterwarnings(
action="ignore", module="twisted_private_helper")
from twisted_private_helper import module
module.callTestFunction()
warningsShown = self.flushWarnings()
self.assertEqual(len(warningsShown), 0) | L{deprecate.warnAboutFunction} emits a warning that will be filtered if
L{warnings.filterwarning} is called with the module name of the
deprecated function. | test_filteredWarning | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_filteredOnceWarning(self):
"""
L{deprecate.warnAboutFunction} emits a warning that will be filtered
once if L{warnings.filterwarning} is called with the module name of the
deprecated function and an action of once.
"""
# Clean up anything *else* that might spuriously filter out the warning,
# such as the "always" simplefilter set up by unittest._collectWarnings.
# We'll also rely on trial to restore the original filters afterwards.
del warnings.filters[:]
warnings.filterwarnings(
action="module", module="twisted_private_helper")
from twisted_private_helper import module
module.callTestFunction()
module.callTestFunction()
warningsShown = self.flushWarnings()
self.assertEqual(len(warningsShown), 1)
message = warningsShown[0]['message']
category = warningsShown[0]['category']
filename = warningsShown[0]['filename']
lineno = warningsShown[0]['lineno']
msg = warnings.formatwarning(message, category, filename, lineno)
self.assertTrue(
msg.endswith("module.py:9: DeprecationWarning: A Warning String\n"
" return a\n"),
"Unexpected warning string: %r" % (msg,)) | L{deprecate.warnAboutFunction} emits a warning that will be filtered
once if L{warnings.filterwarning} is called with the module name of the
deprecated function and an action of once. | test_filteredOnceWarning | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def dummyCallable():
"""
Do nothing.
This is used to test the deprecation decorators.
""" | Do nothing.
This is used to test the deprecation decorators. | dummyCallable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def dummyReplacementMethod():
"""
Do nothing.
This is used to test the replacement parameter to L{deprecated}.
""" | Do nothing.
This is used to test the replacement parameter to L{deprecated}. | dummyReplacementMethod | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_getDeprecationWarningString(self):
"""
L{getDeprecationWarningString} returns a string that tells us that a
callable was deprecated at a certain released version of Twisted.
"""
version = Version('Twisted', 8, 0, 0)
self.assertEqual(
getDeprecationWarningString(self.test_getDeprecationWarningString,
version),
"%s.DeprecationWarningsTests.test_getDeprecationWarningString "
"was deprecated in Twisted 8.0.0" % (__name__,)) | L{getDeprecationWarningString} returns a string that tells us that a
callable was deprecated at a certain released version of Twisted. | test_getDeprecationWarningString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_getDeprecationWarningStringWithFormat(self):
"""
L{getDeprecationWarningString} returns a string that tells us that a
callable was deprecated at a certain released version of Twisted, with
a message containing additional information about the deprecation.
"""
version = Version('Twisted', 8, 0, 0)
format = DEPRECATION_WARNING_FORMAT + ': This is a message'
self.assertEqual(
getDeprecationWarningString(self.test_getDeprecationWarningString,
version, format),
'%s.DeprecationWarningsTests.test_getDeprecationWarningString was '
'deprecated in Twisted 8.0.0: This is a message' % (__name__,)) | L{getDeprecationWarningString} returns a string that tells us that a
callable was deprecated at a certain released version of Twisted, with
a message containing additional information about the deprecation. | test_getDeprecationWarningStringWithFormat | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_deprecateEmitsWarning(self):
"""
Decorating a callable with L{deprecated} emits a warning.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
def addStackLevel():
dummy()
with catch_warnings(record=True) as caught:
simplefilter("always")
addStackLevel()
self.assertEqual(caught[0].category, DeprecationWarning)
self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version))
# rstrip in case .pyc/.pyo
self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co')) | Decorating a callable with L{deprecated} emits a warning. | test_deprecateEmitsWarning | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_deprecatedPreservesName(self):
"""
The decorated function has the same name as the original.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
self.assertEqual(dummyCallable.__name__, dummy.__name__)
self.assertEqual(fullyQualifiedName(dummyCallable),
fullyQualifiedName(dummy)) | The decorated function has the same name as the original. | test_deprecatedPreservesName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_getDeprecationDocstring(self):
"""
L{_getDeprecationDocstring} returns a note about the deprecation to go
into a docstring.
"""
version = Version('Twisted', 8, 0, 0)
self.assertEqual(
"Deprecated in Twisted 8.0.0.",
_getDeprecationDocstring(version, '')) | L{_getDeprecationDocstring} returns a note about the deprecation to go
into a docstring. | test_getDeprecationDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_deprecatedUpdatesDocstring(self):
"""
The docstring of the deprecated function is appended with information
about the deprecation.
"""
def localDummyCallable():
"""
Do nothing.
This is used to test the deprecation decorators.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(localDummyCallable)
_appendToDocstring(
localDummyCallable,
_getDeprecationDocstring(version, ''))
self.assertEqual(localDummyCallable.__doc__, dummy.__doc__) | The docstring of the deprecated function is appended with information
about the deprecation. | test_deprecatedUpdatesDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_versionMetadata(self):
"""
Deprecating a function adds version information to the decorated
version of that function.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
self.assertEqual(version, dummy.deprecatedVersion) | Deprecating a function adds version information to the decorated
version of that function. | test_versionMetadata | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_getDeprecationWarningStringReplacement(self):
"""
L{getDeprecationWarningString} takes an additional replacement parameter
that can be used to add information to the deprecation. If the
replacement parameter is a string, it will be interpolated directly into
the result.
"""
version = Version('Twisted', 8, 0, 0)
warningString = getDeprecationWarningString(
self.test_getDeprecationWarningString, version,
replacement="something.foobar")
self.assertEqual(
warningString,
"%s was deprecated in Twisted 8.0.0; please use something.foobar "
"instead" % (
fullyQualifiedName(self.test_getDeprecationWarningString),)) | L{getDeprecationWarningString} takes an additional replacement parameter
that can be used to add information to the deprecation. If the
replacement parameter is a string, it will be interpolated directly into
the result. | test_getDeprecationWarningStringReplacement | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_getDeprecationWarningStringReplacementWithCallable(self):
"""
L{getDeprecationWarningString} takes an additional replacement parameter
that can be used to add information to the deprecation. If the
replacement parameter is a callable, its fully qualified name will be
interpolated into the result.
"""
version = Version('Twisted', 8, 0, 0)
warningString = getDeprecationWarningString(
self.test_getDeprecationWarningString, version,
replacement=dummyReplacementMethod)
self.assertEqual(
warningString,
"%s was deprecated in Twisted 8.0.0; please use "
"%s.dummyReplacementMethod instead" % (
fullyQualifiedName(self.test_getDeprecationWarningString),
__name__)) | L{getDeprecationWarningString} takes an additional replacement parameter
that can be used to add information to the deprecation. If the
replacement parameter is a callable, its fully qualified name will be
interpolated into the result. | test_getDeprecationWarningStringReplacementWithCallable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def someProperty(self):
"""
Getter docstring.
@return: The property.
"""
return self._someProtectedValue | Getter docstring.
@return: The property. | someProperty | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def someProperty(self, value):
"""
Setter docstring.
"""
self._someProtectedValue = value | Setter docstring. | someProperty | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def assertDocstring(self, target, expected):
"""
Check that C{target} object has the C{expected} docstring lines.
@param target: Object which is checked.
@type target: C{anything}
@param expected: List of lines, ignoring empty lines or leading or
trailing spaces.
@type expected: L{list} or L{str}
"""
self.assertEqual(
expected,
[x.strip() for x in target.__doc__.splitlines() if x.strip()]
) | Check that C{target} object has the C{expected} docstring lines.
@param target: Object which is checked.
@type target: C{anything}
@param expected: List of lines, ignoring empty lines or leading or
trailing spaces.
@type expected: L{list} or L{str} | assertDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_propertyGetter(self):
"""
When L{deprecatedProperty} is used on a C{property}, accesses raise a
L{DeprecationWarning} and getter docstring is updated to inform the
version in which it was deprecated. C{deprecatedVersion} attribute is
also set to inform the deprecation version.
"""
obj = ClassWithDeprecatedProperty()
obj.someProperty
self.assertDocstring(
ClassWithDeprecatedProperty.someProperty,
[
'Getter docstring.',
'@return: The property.',
'Deprecated in Twisted 1.2.3.',
],
)
ClassWithDeprecatedProperty.someProperty.deprecatedVersion = Version(
'Twisted', 1, 2, 3)
message = (
'twisted.python.test.test_deprecate.ClassWithDeprecatedProperty.'
'someProperty was deprecated in Twisted 1.2.3'
)
warnings = self.flushWarnings([self.test_propertyGetter])
self.assertEqual(1, len(warnings))
self.assertEqual(DeprecationWarning, warnings[0]['category'])
self.assertEqual(message, warnings[0]['message']) | When L{deprecatedProperty} is used on a C{property}, accesses raise a
L{DeprecationWarning} and getter docstring is updated to inform the
version in which it was deprecated. C{deprecatedVersion} attribute is
also set to inform the deprecation version. | test_propertyGetter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_propertySetter(self):
"""
When L{deprecatedProperty} is used on a C{property}, setter accesses
raise a L{DeprecationWarning}.
"""
newValue = object()
obj = ClassWithDeprecatedProperty()
obj.someProperty = newValue
self.assertIs(newValue, obj._someProtectedValue)
message = (
'twisted.python.test.test_deprecate.ClassWithDeprecatedProperty.'
'someProperty was deprecated in Twisted 1.2.3'
)
warnings = self.flushWarnings([self.test_propertySetter])
self.assertEqual(1, len(warnings))
self.assertEqual(DeprecationWarning, warnings[0]['category'])
self.assertEqual(message, warnings[0]['message']) | When L{deprecatedProperty} is used on a C{property}, setter accesses
raise a L{DeprecationWarning}. | test_propertySetter | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_class(self):
"""
When L{deprecated} is used on a class, instantiations raise a
L{DeprecationWarning} and class's docstring is updated to inform the
version in which it was deprecated. C{deprecatedVersion} attribute is
also set to inform the deprecation version.
"""
DeprecatedClass()
self.assertDocstring(
DeprecatedClass,
[('Class which is entirely deprecated without having a '
'replacement.'),
'Deprecated in Twisted 1.2.3.'],
)
DeprecatedClass.deprecatedVersion = Version('Twisted', 1, 2, 3)
message = (
'twisted.python.test.test_deprecate.DeprecatedClass '
'was deprecated in Twisted 1.2.3'
)
warnings = self.flushWarnings([self.test_class])
self.assertEqual(1, len(warnings))
self.assertEqual(DeprecationWarning, warnings[0]['category'])
self.assertEqual(message, warnings[0]['message']) | When L{deprecated} is used on a class, instantiations raise a
L{DeprecationWarning} and class's docstring is updated to inform the
version in which it was deprecated. C{deprecatedVersion} attribute is
also set to inform the deprecation version. | test_class | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_deprecatedReplacement(self):
"""
L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a string, it will be interpolated directly
into the warning message.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version, "something.foobar")(dummyCallable)
self.assertEqual(dummy.__doc__,
"\n"
" Do nothing.\n\n"
" This is used to test the deprecation decorators.\n\n"
" Deprecated in Twisted 8.0.0; please use "
"something.foobar"
" instead.\n"
" ") | L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a string, it will be interpolated directly
into the warning message. | test_deprecatedReplacement | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_deprecatedReplacementWithCallable(self):
"""
L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a callable, its fully qualified name will
be interpolated into the warning message.
"""
version = Version('Twisted', 8, 0, 0)
decorator = deprecated(version, replacement=dummyReplacementMethod)
dummy = decorator(dummyCallable)
self.assertEqual(dummy.__doc__,
"\n"
" Do nothing.\n\n"
" This is used to test the deprecation decorators.\n\n"
" Deprecated in Twisted 8.0.0; please use "
"%s.dummyReplacementMethod instead.\n"
" " % (__name__,)) | L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a callable, its fully qualified name will
be interpolated into the warning message. | test_deprecatedReplacementWithCallable | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_appendToEmptyDocstring(self):
"""
Appending to an empty docstring simply replaces the docstring.
"""
def noDocstring():
pass
_appendToDocstring(noDocstring, "Appended text.")
self.assertEqual("Appended text.", noDocstring.__doc__) | Appending to an empty docstring simply replaces the docstring. | test_appendToEmptyDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def singleLineDocstring():
"""This doesn't comply with standards, but is here for a test.""" | This doesn't comply with standards, but is here for a test. | test_appendToSingleLineDocstring.singleLineDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_appendToSingleLineDocstring(self):
"""
Appending to a single line docstring places the message on a new line,
with a blank line separating it from the rest of the docstring.
The docstring ends with a newline, conforming to Twisted and PEP 8
standards. Unfortunately, the indentation is incorrect, since the
existing docstring doesn't have enough info to help us indent
properly.
"""
def singleLineDocstring():
"""This doesn't comply with standards, but is here for a test."""
_appendToDocstring(singleLineDocstring, "Appended text.")
self.assertEqual(
["This doesn't comply with standards, but is here for a test.",
"",
"Appended text."],
singleLineDocstring.__doc__.splitlines())
self.assertTrue(singleLineDocstring.__doc__.endswith('\n')) | Appending to a single line docstring places the message on a new line,
with a blank line separating it from the rest of the docstring.
The docstring ends with a newline, conforming to Twisted and PEP 8
standards. Unfortunately, the indentation is incorrect, since the
existing docstring doesn't have enough info to help us indent
properly. | test_appendToSingleLineDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def multiLineDocstring():
"""
This is a multi-line docstring.
""" | This is a multi-line docstring. | test_appendToMultilineDocstring.multiLineDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def expectedDocstring():
"""
This is a multi-line docstring.
Appended text.
""" | This is a multi-line docstring.
Appended text. | test_appendToMultilineDocstring.expectedDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_appendToMultilineDocstring(self):
"""
Appending to a multi-line docstring places the messade on a new line,
with a blank line separating it from the rest of the docstring.
Because we have multiple lines, we have enough information to do
indentation.
"""
def multiLineDocstring():
"""
This is a multi-line docstring.
"""
def expectedDocstring():
"""
This is a multi-line docstring.
Appended text.
"""
_appendToDocstring(multiLineDocstring, "Appended text.")
self.assertEqual(
expectedDocstring.__doc__, multiLineDocstring.__doc__) | Appending to a multi-line docstring places the messade on a new line,
with a blank line separating it from the rest of the docstring.
Because we have multiple lines, we have enough information to do
indentation. | test_appendToMultilineDocstring | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def checkPassed(self, func, *args, **kw):
"""
Test an invocation of L{passed} with the given function, arguments, and
keyword arguments.
@param func: A function whose argspec will be inspected.
@type func: A callable.
@param args: The arguments which could be passed to C{func}.
@param kw: The keyword arguments which could be passed to C{func}.
@return: L{_passedSignature} or L{_passedArgSpec}'s return value
@rtype: L{dict}
"""
if getattr(inspect, "signature", None):
# Python 3
return _passedSignature(inspect.signature(func), args, kw)
else:
# Python 2
return _passedArgSpec(inspect.getargspec(func), args, kw) | Test an invocation of L{passed} with the given function, arguments, and
keyword arguments.
@param func: A function whose argspec will be inspected.
@type func: A callable.
@param args: The arguments which could be passed to C{func}.
@param kw: The keyword arguments which could be passed to C{func}.
@return: L{_passedSignature} or L{_passedArgSpec}'s return value
@rtype: L{dict} | checkPassed | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_simplePositional(self):
"""
L{passed} identifies the arguments passed by a simple
positional test.
"""
def func(a, b):
pass
self.assertEqual(self.checkPassed(func, 1, 2), dict(a=1, b=2)) | L{passed} identifies the arguments passed by a simple
positional test. | test_passed_simplePositional | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_tooManyArgs(self):
"""
L{passed} raises a L{TypeError} if too many arguments are
passed.
"""
def func(a, b):
pass
self.assertRaises(TypeError, self.checkPassed, func, 1, 2, 3) | L{passed} raises a L{TypeError} if too many arguments are
passed. | test_passed_tooManyArgs | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_doublePassKeyword(self):
"""
L{passed} raises a L{TypeError} if a argument is passed both
positionally and by keyword.
"""
def func(a):
pass
self.assertRaises(TypeError, self.checkPassed, func, 1, a=2) | L{passed} raises a L{TypeError} if a argument is passed both
positionally and by keyword. | test_passed_doublePassKeyword | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_unspecifiedKeyword(self):
"""
L{passed} raises a L{TypeError} if a keyword argument not
present in the function's declaration is passed.
"""
def func(a):
pass
self.assertRaises(TypeError, self.checkPassed, func, 1, z=2) | L{passed} raises a L{TypeError} if a keyword argument not
present in the function's declaration is passed. | test_passed_unspecifiedKeyword | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_star(self):
"""
L{passed} places additional positional arguments into a tuple
under the name of the star argument.
"""
def func(a, *b):
pass
self.assertEqual(self.checkPassed(func, 1, 2, 3),
dict(a=1, b=(2, 3))) | L{passed} places additional positional arguments into a tuple
under the name of the star argument. | test_passed_star | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_starStar(self):
"""
Additional keyword arguments are passed as a dict to the star star
keyword argument.
"""
def func(a, **b):
pass
self.assertEqual(self.checkPassed(func, 1, x=2, y=3, z=4),
dict(a=1, b=dict(x=2, y=3, z=4))) | Additional keyword arguments are passed as a dict to the star star
keyword argument. | test_passed_starStar | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_passed_noDefaultValues(self):
"""
The results of L{passed} only include arguments explicitly
passed, not default values.
"""
def func(a, b, c=1, d=2, e=3):
pass
self.assertEqual(self.checkPassed(func, 1, 2, e=7),
dict(a=1, b=2, e=7)) | The results of L{passed} only include arguments explicitly
passed, not default values. | test_passed_noDefaultValues | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_mutualExclusionPrimeDirective(self):
"""
L{mutuallyExclusiveArguments} does not interfere in its
decoratee's operation, either its receipt of arguments or its return
value.
"""
@_mutuallyExclusiveArguments([('a', 'b')])
def func(x, y, a=3, b=4):
return x + y + a + b
self.assertEqual(func(1, 2), 10)
self.assertEqual(func(1, 2, 7), 14)
self.assertEqual(func(1, 2, b=7), 13) | L{mutuallyExclusiveArguments} does not interfere in its
decoratee's operation, either its receipt of arguments or its return
value. | test_mutualExclusionPrimeDirective | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_mutualExclusionExcludesByKeyword(self):
"""
L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
decoratee is passed a pair of mutually exclusive arguments.
"""
@_mutuallyExclusiveArguments([['a', 'b']])
def func(a=3, b=4):
return a + b
self.assertRaises(TypeError, func, a=3, b=4) | L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
decoratee is passed a pair of mutually exclusive arguments. | test_mutualExclusionExcludesByKeyword | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def test_invalidParameterType(self):
"""
Create a fake signature with an invalid parameter
type to test error handling. The valid parameter
types are specified in L{inspect.Parameter}.
"""
class FakeSignature:
def __init__(self, parameters):
self.parameters = parameters
class FakeParameter:
def __init__(self, name, kind):
self.name = name
self.kind = kind
def func(a, b):
pass
func(1, 2)
parameters = inspect.signature(func).parameters
dummyParameters = parameters.copy()
dummyParameters['c'] = FakeParameter("fake", "fake")
fakeSig = FakeSignature(dummyParameters)
self.assertRaises(TypeError, _passedSignature, fakeSig, (1, 2), {}) | Create a fake signature with an invalid parameter
type to test error handling. The valid parameter
types are specified in L{inspect.Parameter}. | test_invalidParameterType | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py | MIT |
def mktemp(self):
"""
Make our own directory.
"""
newDir = tempfile.mkdtemp(dir=u"/tmp/")
self.addCleanup(shutil.rmtree, newDir)
return newDir | Make our own directory. | mktemp | 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 _gitConfig(path):
"""
Set some config in the repo that Git requires to make commits. This isn't
needed in real usage, just for tests.
@param path: The path to the Git repository.
@type path: L{FilePath}
"""
runCommand(["git", "config",
"--file", path.child(".git").child("config").path,
"user.name", '"someone"'])
runCommand(["git", "config",
"--file", path.child(".git").child("config").path,
"user.email", '"[email protected]"']) | Set some config in the repo that Git requires to make commits. This isn't
needed in real usage, just for tests.
@param path: The path to the Git repository.
@type path: L{FilePath} | _gitConfig | 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 _gitInit(path):
"""
Run a git init, and set some config that git requires. This isn't needed in
real usage.
@param path: The path to where the Git repo will be created.
@type path: L{FilePath}
"""
runCommand(["git", "init", path.path])
_gitConfig(path) | Run a git init, and set some config that git requires. This isn't needed in
real usage.
@param path: The path to where the Git repo will be created.
@type path: L{FilePath} | _gitInit | 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 genVersion(*args, **kwargs):
"""
A convenience for generating _version.py data.
@param args: Arguments to pass to L{Version}.
@param kwargs: Keyword arguments to pass to L{Version}.
"""
return (u"from incremental import Version\n__version__={!r}".format(
Version(*args, **kwargs))) | A convenience for generating _version.py data.
@param args: Arguments to pass to L{Version}.
@param kwargs: Keyword arguments to pass to L{Version}. | genVersion | 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 createStructure(self, root, dirDict):
"""
Create a set of directories and files given a dict defining their
structure.
@param root: The directory in which to create the structure. It must
already exist.
@type root: L{FilePath}
@param dirDict: The dict defining the structure. Keys should be strings
naming files, values should be strings describing file contents OR
dicts describing subdirectories. All files are written in binary
mode. Any string values are assumed to describe text files and
will have their newlines replaced with the platform-native newline
convention. For example::
{"foofile": "foocontents",
"bardir": {"barfile": "bar\ncontents"}}
@type dirDict: C{dict}
"""
for x in dirDict:
child = root.child(x)
if isinstance(dirDict[x], dict):
child.createDirectory()
self.createStructure(child, dirDict[x])
else:
child.setContent(dirDict[x].replace('\n', os.linesep).encode("utf-8")) | Create a set of directories and files given a dict defining their
structure.
@param root: The directory in which to create the structure. It must
already exist.
@type root: L{FilePath}
@param dirDict: The dict defining the structure. Keys should be strings
naming files, values should be strings describing file contents OR
dicts describing subdirectories. All files are written in binary
mode. Any string values are assumed to describe text files and
will have their newlines replaced with the platform-native newline
convention. For example::
{"foofile": "foocontents",
"bardir": {"barfile": "bar\ncontents"}}
@type dirDict: C{dict} | createStructure | 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 assertStructure(self, root, dirDict):
"""
Assert that a directory is equivalent to one described by a dict.
@param root: The filesystem directory to compare.
@type root: L{FilePath}
@param dirDict: The dict that should describe the contents of the
directory. It should be the same structure as the C{dirDict}
parameter to L{createStructure}.
@type dirDict: C{dict}
"""
children = [each.basename() for each in root.children()]
for pathSegment, expectation in dirDict.items():
child = root.child(pathSegment)
if callable(expectation):
self.assertTrue(expectation(child))
elif isinstance(expectation, dict):
self.assertTrue(child.isdir(), "{} is not a dir!".format(
child.path))
self.assertStructure(child, expectation)
else:
actual = child.getContent().decode("utf-8").replace(os.linesep, u'\n')
self.assertEqual(actual, expectation)
children.remove(pathSegment)
if children:
self.fail("There were extra children in %s: %s"
% (root.path, children)) | Assert that a directory is equivalent to one described by a dict.
@param root: The filesystem directory to compare.
@type root: L{FilePath}
@param dirDict: The dict that should describe the contents of the
directory. It should be the same structure as the C{dirDict}
parameter to L{createStructure}.
@type dirDict: C{dict} | assertStructure | 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 assertProjectsEqual(self, observedProjects, expectedProjects):
"""
Assert that two lists of L{Project}s are equal.
"""
self.assertEqual(len(observedProjects), len(expectedProjects))
observedProjects = sorted(observedProjects,
key=operator.attrgetter('directory'))
expectedProjects = sorted(expectedProjects,
key=operator.attrgetter('directory'))
for observed, expected in zip(observedProjects, expectedProjects):
self.assertEqual(observed.directory, expected.directory) | Assert that two lists of L{Project}s are equal. | assertProjectsEqual | 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 makeProject(self, version, baseDirectory=None):
"""
Make a Twisted-style project in the given base directory.
@param baseDirectory: The directory to create files in
(as a L{FilePath).
@param version: The version information for the project.
@return: L{Project} pointing to the created project.
"""
if baseDirectory is None:
baseDirectory = FilePath(self.mktemp())
segments = version[0].split('.')
directory = baseDirectory
for segment in segments:
directory = directory.child(segment)
if not directory.exists():
directory.createDirectory()
directory.child('__init__.py').setContent(b'')
directory.child('newsfragments').createDirectory()
directory.child('_version.py').setContent(genVersion(*version).encode("utf-8"))
return Project(directory) | Make a Twisted-style project in the given base directory.
@param baseDirectory: The directory to create files in
(as a L{FilePath).
@param version: The version information for the project.
@return: L{Project} pointing to the created project. | makeProject | 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 makeProjects(self, *versions):
"""
Create a series of projects underneath a temporary base directory.
@return: A L{FilePath} for the base directory.
"""
baseDirectory = FilePath(self.mktemp())
for version in versions:
self.makeProject(version, baseDirectory)
return baseDirectory | Create a series of projects underneath a temporary base directory.
@return: A L{FilePath} for the base directory. | makeProjects | 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_getVersion(self):
"""
Project objects know their version.
"""
version = ('twisted', 2, 1, 0)
project = self.makeProject(version)
self.assertEqual(project.getVersion(), Version(*version)) | Project objects know their version. | test_getVersion | 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_repr(self):
"""
The representation of a Project is Project(directory).
"""
foo = Project(FilePath('bar'))
self.assertEqual(
repr(foo), 'Project(%r)' % (foo.directory)) | The representation of a Project is Project(directory). | test_repr | 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_findTwistedStyleProjects(self):
"""
findTwistedStyleProjects finds all projects underneath a particular
directory. A 'project' is defined by the existence of a 'newsfragments'
directory and is returned as a Project object.
"""
baseDirectory = self.makeProjects(
('foo', 2, 3, 0), ('foo.bar', 0, 7, 4))
projects = findTwistedProjects(baseDirectory)
self.assertProjectsEqual(
projects,
[Project(baseDirectory.child('foo')),
Project(baseDirectory.child('foo').child('bar'))]) | findTwistedStyleProjects finds all projects underneath a particular
directory. A 'project' is defined by the existence of a 'newsfragments'
directory and is returned as a Project object. | test_findTwistedStyleProjects | 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_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 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_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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.