source stringclasses 1
value | version stringclasses 1
value | module stringclasses 43
values | function stringclasses 307
values | input stringlengths 3 496 | expected stringlengths 0 40.5k | signature stringclasses 0
values |
|---|---|---|---|---|---|---|
cpython | cfcd524 | doctest | DebugRunner | >>> test = DocTestParser().get_doctest('''
... >>> x = 2
... ''', {}, 'foo', 'foo.py', 0) | null | |
cpython | cfcd524 | doctest | DebugRunner | >>> runner.run(test) | TestResults(failed=0, attempted=1) | null |
cpython | cfcd524 | doctest | DebugRunner | >>> test.globs | {} | null |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> import doctest | null | |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> old = doctest._unittest_reportflags | null | |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> doctest.set_unittest_reportflags(REPORT_NDIFF |
... REPORT_ONLY_FIRST_FAILURE) == old | True | null |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> doctest._unittest_reportflags == (REPORT_NDIFF |
... REPORT_ONLY_FIRST_FAILURE) | True
Only reporting flags can be set: | null |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> doctest.set_unittest_reportflags(ELLIPSIS) | Traceback (most recent call last):
...
ValueError: ('Only reporting flags allowed', 8) | null |
cpython | cfcd524 | doctest | doctest.set_unittest_reportflags | >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF |
... REPORT_ONLY_FIRST_FAILURE) | True | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
... {}, 'foo', 'foo.py', 0) | null | |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> case = DocTestCase(test) | null | |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> try:
... case.debug()
... except UnexpectedException as f:
... failure = f | The UnexpectedException contains the test, the example, and
the original exception: | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> failure.test is test | True | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> failure.example.want | '42\n' | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> exc_info = failure.exc_info | null | |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> raise exc_info[1] # Already has the traceback | Traceback (most recent call last):
...
KeyError
If the output doesn't match, then a DocTestFailure is raised: | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> test = DocTestParser().get_doctest('''
... >>> x = 1
... >>> x
... 2
... ''', {}, 'foo', 'foo.py', 0) | null | |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> case = DocTestCase(test) | null | |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> try:
... case.debug()
... except DocTestFailure as f:
... failure = f | DocTestFailure objects provide access to the test: | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> failure.test is test | True
As well as to the example: | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> failure.example.want | '2\n'
and the actual output: | null |
cpython | cfcd524 | doctest | DocTestCase.debug | >>> failure.got | '1\n' | null |
cpython | cfcd524 | doctest | DocFileCase.script_from_examples | >>> text = '''
... Here are examples of simple math.
...
... Python has super accurate integer addition
...
... >>> 2 + 2
... 5
...
... And very friendly error messages:
...
... >>> 1/0
... To Infinity
... And
... Beyond
...
... ... | null | |
cpython | cfcd524 | doctest | DocFileCase.script_from_examples | >>> print(script_from_examples(text)) | # Here are examples of simple math.
#
# Python has super accurate integer addition
#
2 + 2
# Expected:
## 5
#
# And very friendly error messages:
#
1/0
# Expected:
## To Infinity
## And
## Beyond
#
# You can use logic if you want:
#
if 0:
blah
blah
#
# Ho hum
<BLANKLINE> | null |
cpython | cfcd524 | doctest | _TestClass | >>> _TestClass(13).get() + _TestClass(-12).get() | 1 | null |
cpython | cfcd524 | doctest | _TestClass | >>> hex(_TestClass(13).square().get()) | '0xa9' | null |
cpython | cfcd524 | doctest | _TestClass.__init__ | >>> t = _TestClass(123) | null | |
cpython | cfcd524 | doctest | _TestClass.__init__ | >>> print(t.get()) | 123 | null |
cpython | cfcd524 | doctest | _TestClass.square | >>> _TestClass(13).square().get() | 169 | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> x = _TestClass(-42) | null | |
cpython | cfcd524 | doctest | _TestClass.get | >>> print(x.get()) | -42 | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> x = 1; y = 2 | null | |
cpython | cfcd524 | doctest | _TestClass.get | >>> x + y, x * y | (3, 2) | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> 4 == 4 | 1 | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> 4 == 4 | True | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> 4 > 4 | 0 | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> 4 > 4 | False | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> print('foo\n\nbar\n') | foo
<BLANKLINE>
bar
<BLANKLINE> | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> print(list(range(1000))) #doctest: +ELLIPSIS | [0, 1, 2, ..., 999] | null |
cpython | cfcd524 | doctest | _TestClass.get | >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29] | null |
cpython | cfcd524 | zipfile._path.glob | Translator | >>> Translator('xyz') | Traceback (most recent call last):
...
AssertionError: Invalid separators | null |
cpython | cfcd524 | zipfile._path.glob | Translator | >>> Translator('') | Traceback (most recent call last):
...
AssertionError: Invalid separators | null |
cpython | cfcd524 | zipfile._path.glob | Translator.translate_core | >>> t = Translator() | null | |
cpython | cfcd524 | zipfile._path.glob | Translator.translate_core | >>> t.translate_core('*.txt').replace('\\\\', '') | '[^/]*\\.txt' | null |
cpython | cfcd524 | zipfile._path.glob | Translator.translate_core | >>> t.translate_core('a?txt') | 'a[^/]txt' | null |
cpython | cfcd524 | zipfile._path.glob | Translator.translate_core | >>> t.translate_core('**/*').replace('\\\\', '') | '.*/[^/][^/]*' | null |
cpython | cfcd524 | zipfile._path.glob | Translator.restrict_rglob | >>> Translator().translate('**foo') | Traceback (most recent call last):
...
ValueError: ** must appear alone in a path segment | null |
cpython | cfcd524 | zipfile._path.glob | Translator.separate | >>> [m.group(0) for m in separate('*.txt')] | ['*.txt'] | null |
cpython | cfcd524 | zipfile._path.glob | Translator.separate | >>> [m.group(0) for m in separate('a[?]txt')] | ['a', '[?]', 'txt'] | null |
cpython | cfcd524 | zipfile._path | _parents | >>> list(_parents('b/d')) | ['b'] | null |
cpython | cfcd524 | zipfile._path | _parents | >>> list(_parents('/b/d/')) | ['/b'] | null |
cpython | cfcd524 | zipfile._path | _parents | >>> list(_parents('b/d/f/')) | ['b/d', 'b'] | null |
cpython | cfcd524 | zipfile._path | _parents | >>> list(_parents('b')) | [] | null |
cpython | cfcd524 | zipfile._path | _parents | >>> list(_parents('')) | [] | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('b/d')) | ['b/d', 'b'] | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('/b/d/')) | ['/b/d', '/b'] | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('b/d/f/')) | ['b/d/f', 'b/d', 'b'] | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('b')) | ['b'] | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('')) | []
Multiple separators are treated like a single. | null |
cpython | cfcd524 | zipfile._path | _ancestry | >>> list(_ancestry('//b//d///f//')) | ['//b//d///f', '//b//d', '//b'] | null |
cpython | cfcd524 | zipfile._path | CompleteDirs | >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt'])) | ['foo/', 'foo/bar/'] | null |
cpython | cfcd524 | zipfile._path | CompleteDirs | >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt', 'foo/bar/'])) | ['foo/'] | null |
cpython | cfcd524 | zipfile._path | Path | >>> data = io.BytesIO() | null | |
cpython | cfcd524 | zipfile._path | Path | >>> zf = ZipFile(data, 'w') | null | |
cpython | cfcd524 | zipfile._path | Path | >>> zf.writestr('a.txt', 'content of a') | null | |
cpython | cfcd524 | zipfile._path | Path | >>> zf.writestr('b/c.txt', 'content of c') | null | |
cpython | cfcd524 | zipfile._path | Path | >>> zf.writestr('b/d/e.txt', 'content of e') | null | |
cpython | cfcd524 | zipfile._path | Path | >>> zf.filename = 'mem/abcde.zip' | Path accepts the zipfile object itself or a filename | null |
cpython | cfcd524 | zipfile._path | Path | >>> path = Path(zf) | From there, several path operations are available.
Directory iteration (including the zip file itself): | null |
cpython | cfcd524 | zipfile._path | Path | >>> a, b = path.iterdir() | null | |
cpython | cfcd524 | zipfile._path | Path | >>> a | Path('mem/abcde.zip', 'a.txt') | null |
cpython | cfcd524 | zipfile._path | Path | >>> b | Path('mem/abcde.zip', 'b/')
name property: | null |
cpython | cfcd524 | zipfile._path | Path | >>> b.name | 'b'
join with divide operator: | null |
cpython | cfcd524 | zipfile._path | Path | >>> c = b / 'c.txt' | null | |
cpython | cfcd524 | zipfile._path | Path | >>> c | Path('mem/abcde.zip', 'b/c.txt') | null |
cpython | cfcd524 | zipfile._path | Path | >>> c.name | 'c.txt'
Read text: | null |
cpython | cfcd524 | zipfile._path | Path | >>> c.read_text(encoding='utf-8') | 'content of c'
existence: | null |
cpython | cfcd524 | zipfile._path | Path | >>> c.exists() | True | null |
cpython | cfcd524 | zipfile._path | Path | >>> (b / 'missing.txt').exists() | False
Coercion to string: | null |
cpython | cfcd524 | zipfile._path | Path | >>> import os | null | |
cpython | cfcd524 | zipfile._path | Path | >>> str(c).replace(os.sep, posixpath.sep) | 'mem/abcde.zip/b/c.txt'
At the root, ``name``, ``filename``, and ``parent``
resolve to the zipfile. | null |
cpython | cfcd524 | zipfile._path | Path | >>> str(path) | 'mem/abcde.zip/' | null |
cpython | cfcd524 | zipfile._path | Path | >>> path.name | 'abcde.zip' | null |
cpython | cfcd524 | zipfile._path | Path | >>> path.filename == pathlib.Path('mem/abcde.zip') | True | null |
cpython | cfcd524 | zipfile._path | Path | >>> str(path.parent) | 'mem'
If the zipfile has no filename, such attributes are not
valid and accessing them will raise an Exception. | null |
cpython | cfcd524 | zipfile._path | Path | >>> zf.filename = None | null | |
cpython | cfcd524 | zipfile._path | Path | >>> path.name | Traceback (most recent call last):
...
TypeError: ... | null |
cpython | cfcd524 | zipfile._path | Path | >>> path.filename | Traceback (most recent call last):
...
TypeError: ... | null |
cpython | cfcd524 | zipfile._path | Path | >>> path.parent | Traceback (most recent call last):
...
TypeError: ...
# workaround python/cpython#106763 | null |
cpython | cfcd524 | zipfile._path | Path | >>> pass | null | |
cpython | cfcd524 | zipfile._path | Path.__eq__ | >>> Path(zipfile.ZipFile(io.BytesIO(), 'w')) == 'foo' | False | null |
cpython | cfcd524 | poplib | POP3.capa | >>> c=poplib.POP3('localhost') | null | |
cpython | cfcd524 | poplib | POP3.capa | >>> c.capa() | {'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
'UIDL': [], 'RESP-CODES': []} | null |
cpython | cfcd524 | poplib | POP3.capa | >>> | Really, according to RFC 2449, the cyrus folks should avoid
having the implementation split into multiple arguments... | null |
cpython | cfcd524 | difflib | SequenceMatcher | >>> s = SequenceMatcher(lambda x: x == " ",
... "private Thread currentThread;",
... "private volatile Thread currentThread;") | null | |
cpython | cfcd524 | difflib | SequenceMatcher | >>> | .ratio() returns a float in [0, 1], measuring the "similarity" of the
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
sequences are close matches: | null |
cpython | cfcd524 | difflib | SequenceMatcher | >>> print(round(s.ratio(), 2)) | 0.87 | null |
cpython | cfcd524 | difflib | SequenceMatcher | >>> | If you're only interested in where the sequences match,
.get_matching_blocks() is handy: | null |
cpython | cfcd524 | difflib | SequenceMatcher | >>> for block in s.get_matching_blocks():
... print("a[%d] and b[%d] match for %d elements" % block) | a[0] and b[0] match for 8 elements
a[8] and b[17] match for 21 elements
a[29] and b[38] match for 0 elements
Note that the last tuple returned by .get_matching_blocks() is always a
dummy, (len(a), len(b), 0), and this is the only case in which the last
tuple element (number of elements matched) is 0.
If you want to k... | null |
cpython | cfcd524 | difflib | SequenceMatcher | >>> for opcode in s.get_opcodes():
... print("%6s a[%d:%d] b[%d:%d]" % opcode) | equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:29] b[17:38]
See the Differ class for a fancy human-friendly file differencer, which
uses SequenceMatcher both to compare sequences of lines, and to compare
sequences of characters within similar (near-matching) lines.
See also function get_close_matches() in this... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.