Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
BaseContext.__delitem__ | (self, key) | Delete a variable from the current context | Delete a variable from the current context | def __delitem__(self, key):
"Delete a variable from the current context"
del self.dicts[-1][key] | [
"def",
"__delitem__",
"(",
"self",
",",
"key",
")",
":",
"del",
"self",
".",
"dicts",
"[",
"-",
"1",
"]",
"[",
"key",
"]"
] | [
71,
4
] | [
73,
31
] | python | en | ['en', 'en', 'en'] | True |
BaseContext.new | (self, values=None) |
Returns a new context with the same properties, but with only the
values given in 'values' stored.
|
Returns a new context with the same properties, but with only the
values given in 'values' stored.
| def new(self, values=None):
"""
Returns a new context with the same properties, but with only the
values given in 'values' stored.
"""
new_context = copy(self)
new_context._reset_dicts(values)
return new_context | [
"def",
"new",
"(",
"self",
",",
"values",
"=",
"None",
")",
":",
"new_context",
"=",
"copy",
"(",
"self",
")",
"new_context",
".",
"_reset_dicts",
"(",
"values",
")",
"return",
"new_context"
] | [
90,
4
] | [
97,
26
] | python | en | ['en', 'error', 'th'] | False |
BaseContext.flatten | (self) |
Returns self.dicts as one dictionary
|
Returns self.dicts as one dictionary
| def flatten(self):
"""
Returns self.dicts as one dictionary
"""
flat = {}
for d in self.dicts:
flat.update(d)
return flat | [
"def",
"flatten",
"(",
"self",
")",
":",
"flat",
"=",
"{",
"}",
"for",
"d",
"in",
"self",
".",
"dicts",
":",
"flat",
".",
"update",
"(",
"d",
")",
"return",
"flat"
] | [
99,
4
] | [
106,
19
] | python | en | ['en', 'error', 'th'] | False |
BaseContext.__eq__ | (self, other) |
Compares two contexts by comparing theirs 'dicts' attributes.
|
Compares two contexts by comparing theirs 'dicts' attributes.
| def __eq__(self, other):
"""
Compares two contexts by comparing theirs 'dicts' attributes.
"""
if isinstance(other, BaseContext):
# because dictionaries can be put in different order
# we have to flatten them like in templates
return self.flatten() == ... | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"BaseContext",
")",
":",
"# because dictionaries can be put in different order",
"# we have to flatten them like in templates",
"return",
"self",
".",
"flatten",
"(",
")",
"==... | [
108,
4
] | [
118,
20
] | python | en | ['en', 'error', 'th'] | False |
Context.update | (self, other_dict) | Pushes other_dict to the stack of dictionaries in the Context | Pushes other_dict to the stack of dictionaries in the Context | def update(self, other_dict):
"Pushes other_dict to the stack of dictionaries in the Context"
if not hasattr(other_dict, '__getitem__'):
raise TypeError('other_dict must be a mapping (dictionary-like) object.')
self.dicts.append(other_dict)
return other_dict | [
"def",
"update",
"(",
"self",
",",
"other_dict",
")",
":",
"if",
"not",
"hasattr",
"(",
"other_dict",
",",
"'__getitem__'",
")",
":",
"raise",
"TypeError",
"(",
"'other_dict must be a mapping (dictionary-like) object.'",
")",
"self",
".",
"dicts",
".",
"append",
... | [
137,
4
] | [
142,
25
] | python | en | ['en', 'en', 'en'] | True |
GetUniqueCheckTests.test_unique_together_normalization | (self) |
Test the Meta.unique_together normalization with different sorts of
objects.
|
Test the Meta.unique_together normalization with different sorts of
objects.
| def test_unique_together_normalization(self):
"""
Test the Meta.unique_together normalization with different sorts of
objects.
"""
data = {
'2-tuple': (('foo', 'bar'),
(('foo', 'bar'),)),
'list': (['foo', 'bar'],
... | [
"def",
"test_unique_together_normalization",
"(",
"self",
")",
":",
"data",
"=",
"{",
"'2-tuple'",
":",
"(",
"(",
"'foo'",
",",
"'bar'",
")",
",",
"(",
"(",
"'foo'",
",",
"'bar'",
")",
",",
")",
")",
",",
"'list'",
":",
"(",
"[",
"'foo'",
",",
"'ba... | [
36,
4
] | [
66,
44
] | python | en | ['en', 'error', 'th'] | False |
show | (ndarray, min_val=None, max_val=None) |
Display an image.
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of the common ranges:
... |
Display an image.
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of the common ranges:
... | def show(ndarray, min_val=None, max_val=None):
"""
Display an image.
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer... | [
"def",
"show",
"(",
"ndarray",
",",
"min_val",
"=",
"None",
",",
"max_val",
"=",
"None",
")",
":",
"# Create a temporary file with the suffix '.png'.",
"fd",
",",
"path",
"=",
"mkstemp",
"(",
"suffix",
"=",
"\".png\"",
")",
"os",
".",
"close",
"(",
"fd",
"... | [
13,
0
] | [
29,
39
] | python | en | ['en', 'error', 'th'] | False |
save | (path, ndarray, min_val=None, max_val=None) |
Save an image, represented as an ndarray, to the filesystem
:param path: string, filepath
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, a... |
Save an image, represented as an ndarray, to the filesystem
:param path: string, filepath
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, a... | def save(path, ndarray, min_val=None, max_val=None):
"""
Save an image, represented as an ndarray, to the filesystem
:param path: string, filepath
:param ndarray: The image as an ndarray
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the im... | [
"def",
"save",
"(",
"path",
",",
"ndarray",
",",
"min_val",
"=",
"None",
",",
"max_val",
"=",
"None",
")",
":",
"as_pil",
"(",
"ndarray",
",",
"min_val",
",",
"max_val",
")",
".",
"save",
"(",
"path",
")"
] | [
32,
0
] | [
44,
48
] | python | en | ['en', 'error', 'th'] | False |
as_pil | (ndarray, min_val=None, max_val=None) |
Converts an ndarray to a PIL image.
:param ndarray: The numpy ndarray to convert
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of... |
Converts an ndarray to a PIL image.
:param ndarray: The numpy ndarray to convert
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified, attempts to
infer whether the image is in any of... | def as_pil(ndarray, min_val=None, max_val=None):
"""
Converts an ndarray to a PIL image.
:param ndarray: The numpy ndarray to convert
:param min_val: The minimum pixel value in the image format
:param max_val: The maximum pixel valie in the image format
If min_val and max_val are not specified... | [
"def",
"as_pil",
"(",
"ndarray",
",",
"min_val",
"=",
"None",
",",
"max_val",
"=",
"None",
")",
":",
"assert",
"isinstance",
"(",
"ndarray",
",",
"np",
".",
"ndarray",
")",
"# rows x cols for grayscale image",
"# rows x cols x channels for color",
"assert",
"ndarr... | [
47,
0
] | [
109,
14
] | python | en | ['en', 'error', 'th'] | False |
make_grid | (image_batch) |
Turns a batch of images into one big image.
:param image_batch: ndarray, shape (batch_size, rows, cols, channels)
:returns : a big image containing all `batch_size` images in a grid
|
Turns a batch of images into one big image.
:param image_batch: ndarray, shape (batch_size, rows, cols, channels)
:returns : a big image containing all `batch_size` images in a grid
| def make_grid(image_batch):
"""
Turns a batch of images into one big image.
:param image_batch: ndarray, shape (batch_size, rows, cols, channels)
:returns : a big image containing all `batch_size` images in a grid
"""
m, ir, ic, ch = image_batch.shape
pad = 3
padded = np.zeros((m, ir +... | [
"def",
"make_grid",
"(",
"image_batch",
")",
":",
"m",
",",
"ir",
",",
"ic",
",",
"ch",
"=",
"image_batch",
".",
"shape",
"pad",
"=",
"3",
"padded",
"=",
"np",
".",
"zeros",
"(",
"(",
"m",
",",
"ir",
"+",
"pad",
"*",
"2",
",",
"ic",
"+",
"pad... | [
112,
0
] | [
141,
15
] | python | en | ['en', 'error', 'th'] | False |
truncate_name | (name, length=None, hash_len=4) | Shortens a string to a repeatable mangled version with the given length.
| Shortens a string to a repeatable mangled version with the given length.
| def truncate_name(name, length=None, hash_len=4):
"""Shortens a string to a repeatable mangled version with the given length.
"""
if length is None or len(name) <= length:
return name
hsh = hashlib.md5(force_bytes(name)).hexdigest()[:hash_len]
return '%s%s' % (name[:length - hash_len], hsh) | [
"def",
"truncate_name",
"(",
"name",
",",
"length",
"=",
"None",
",",
"hash_len",
"=",
"4",
")",
":",
"if",
"length",
"is",
"None",
"or",
"len",
"(",
"name",
")",
"<=",
"length",
":",
"return",
"name",
"hsh",
"=",
"hashlib",
".",
"md5",
"(",
"force... | [
176,
0
] | [
183,
51
] | python | en | ['en', 'en', 'en'] | True |
format_number | (value, max_digits, decimal_places) |
Formats a number into a string with the requisite number of digits and
decimal places.
|
Formats a number into a string with the requisite number of digits and
decimal places.
| def format_number(value, max_digits, decimal_places):
"""
Formats a number into a string with the requisite number of digits and
decimal places.
"""
if isinstance(value, decimal.Decimal):
context = decimal.getcontext().copy()
context.prec = max_digits
return "{0:f}".format(va... | [
"def",
"format_number",
"(",
"value",
",",
"max_digits",
",",
"decimal_places",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"decimal",
".",
"Decimal",
")",
":",
"context",
"=",
"decimal",
".",
"getcontext",
"(",
")",
".",
"copy",
"(",
")",
"context"... | [
186,
0
] | [
196,
47
] | python | en | ['en', 'error', 'th'] | False |
ModelInheritanceTests.test_select_related_defer | (self) |
#23370 - Should be able to defer child fields when using
select_related() from parent to child.
|
#23370 - Should be able to defer child fields when using
select_related() from parent to child.
| def test_select_related_defer(self):
"""
#23370 - Should be able to defer child fields when using
select_related() from parent to child.
"""
Restaurant.objects.create(
name="Demon Dogs",
address="944 W. Fullerton",
serves_hot_dogs=True,
... | [
"def",
"test_select_related_defer",
"(",
"self",
")",
":",
"Restaurant",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"Demon Dogs\"",
",",
"address",
"=",
"\"944 W. Fullerton\"",
",",
"serves_hot_dogs",
"=",
"True",
",",
"serves_pizza",
"=",
"False",
",",
... | [
257,
4
] | [
292,
59
] | python | en | ['en', 'error', 'th'] | False |
ModelInheritanceTests.test_update_query_counts | (self) |
Test that update queries do not generate non-necessary queries.
Refs #18304.
|
Test that update queries do not generate non-necessary queries.
Refs #18304.
| def test_update_query_counts(self):
"""
Test that update queries do not generate non-necessary queries.
Refs #18304.
"""
c = Chef.objects.create(name="Albert")
ir = ItalianRestaurant.objects.create(
name="Ristorante Miron",
address="1234 W. Ash",
... | [
"def",
"test_update_query_counts",
"(",
"self",
")",
":",
"c",
"=",
"Chef",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"Albert\"",
")",
"ir",
"=",
"ItalianRestaurant",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"Ristorante Miron\"",
",",
"a... | [
298,
4
] | [
314,
21
] | python | en | ['en', 'error', 'th'] | False |
ModelInheritanceTests.test_update_parent_filtering | (self) |
Test that updating a field of a model subclass doesn't issue an UPDATE
query constrained by an inner query.
Refs #10399
|
Test that updating a field of a model subclass doesn't issue an UPDATE
query constrained by an inner query.
Refs #10399
| def test_update_parent_filtering(self):
"""
Test that updating a field of a model subclass doesn't issue an UPDATE
query constrained by an inner query.
Refs #10399
"""
supplier = Supplier.objects.create(
name='Central market',
address='610 some str... | [
"def",
"test_update_parent_filtering",
"(",
"self",
")",
":",
"supplier",
"=",
"Supplier",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"'Central market'",
",",
"address",
"=",
"'610 some street'",
")",
"# Capture the expected query in a database agnostic way",
"wit... | [
316,
4
] | [
336,
51
] | python | en | ['en', 'error', 'th'] | False |
queries_captured | (
include_savepoints: bool = False, keep_cache_warm: bool = False
) |
Allow a user to capture just the queries executed during
the with statement.
|
Allow a user to capture just the queries executed during
the with statement.
| def queries_captured(
include_savepoints: bool = False, keep_cache_warm: bool = False
) -> Generator[List[Dict[str, Union[str, bytes]]], None, None]:
"""
Allow a user to capture just the queries executed during
the with statement.
"""
queries: List[Dict[str, Union[str, bytes]]] = []
def wr... | [
"def",
"queries_captured",
"(",
"include_savepoints",
":",
"bool",
"=",
"False",
",",
"keep_cache_warm",
":",
"bool",
"=",
"False",
")",
"->",
"Generator",
"[",
"List",
"[",
"Dict",
"[",
"str",
",",
"Union",
"[",
"str",
",",
"bytes",
"]",
"]",
"]",
","... | [
172,
0
] | [
218,
21
] | python | en | ['en', 'error', 'th'] | False |
stdout_suppressed | () | Redirect stdout to /dev/null. | Redirect stdout to /dev/null. | def stdout_suppressed() -> Iterator[IO[str]]:
"""Redirect stdout to /dev/null."""
with open(os.devnull, "a") as devnull:
stdout, sys.stdout = sys.stdout, devnull
yield stdout
sys.stdout = stdout | [
"def",
"stdout_suppressed",
"(",
")",
"->",
"Iterator",
"[",
"IO",
"[",
"str",
"]",
"]",
":",
"with",
"open",
"(",
"os",
".",
"devnull",
",",
"\"a\"",
")",
"as",
"devnull",
":",
"stdout",
",",
"sys",
".",
"stdout",
"=",
"sys",
".",
"stdout",
",",
... | [
222,
0
] | [
228,
27
] | python | en | ['en', 'en', 'it'] | True |
TestServiceBotBasics.test_service_events_for_private_mentions | (self) | Service bots should not get access to mentions if they aren't a
direct recipient. | Service bots should not get access to mentions if they aren't a
direct recipient. | def test_service_events_for_private_mentions(self) -> None:
"""Service bots should not get access to mentions if they aren't a
direct recipient."""
sender = self.example_user("hamlet")
assert not sender.is_bot
outgoing_bot = self._get_outgoing_bot()
assert outgoing_bot.b... | [
"def",
"test_service_events_for_private_mentions",
"(",
"self",
")",
"->",
"None",
":",
"sender",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"assert",
"not",
"sender",
".",
"is_bot",
"outgoing_bot",
"=",
"self",
".",
"_get_outgoing_bot",
"(",
")",... | [
119,
4
] | [
138,
44
] | python | en | ['en', 'en', 'en'] | True |
make_dataset | (dir, class_to_idx, extensions) | helper to read SVRT dataset
| helper to read SVRT dataset
| def make_dataset(dir, class_to_idx, extensions):
''' helper to read SVRT dataset
'''
images = []
dir = os.path.expanduser(dir)
for root, _, fnames in sorted(os.walk(dir)):
for fname in sorted(fnames):
if has_file_allowed_extension(fname, extensions):
path = os.pa... | [
"def",
"make_dataset",
"(",
"dir",
",",
"class_to_idx",
",",
"extensions",
")",
":",
"images",
"=",
"[",
"]",
"dir",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"dir",
")",
"for",
"root",
",",
"_",
",",
"fnames",
"in",
"sorted",
"(",
"os",
".",... | [
29,
0
] | [
42,
17
] | python | en | ['en', 'no', 'en'] | True |
adjust_learning_rate_svrt | (optimizer, epoch, init_lr, step, epoch_decay) | Sets the learning rate to the initial LR decayed by 10 every epoch_decay epochs | Sets the learning rate to the initial LR decayed by 10 every epoch_decay epochs | def adjust_learning_rate_svrt(optimizer, epoch, init_lr, step, epoch_decay):
"""Sets the learning rate to the initial LR decayed by 10 every epoch_decay epochs"""
lr = init_lr * (0.5 ** (epoch // epoch_decay))
for param_group in optimizer.param_groups:
param_group['lr'] = lr | [
"def",
"adjust_learning_rate_svrt",
"(",
"optimizer",
",",
"epoch",
",",
"init_lr",
",",
"step",
",",
"epoch_decay",
")",
":",
"lr",
"=",
"init_lr",
"*",
"(",
"0.5",
"**",
"(",
"epoch",
"//",
"epoch_decay",
")",
")",
"for",
"param_group",
"in",
"optimizer"... | [
100,
0
] | [
104,
30
] | python | en | ['en', 'en', 'en'] | True |
Deserializer | (stream_or_string, **options) | Deserialize a stream or string of YAML data. | Deserialize a stream or string of YAML data. | def Deserializer(stream_or_string, **options):
"""Deserialize a stream or string of YAML data."""
if isinstance(stream_or_string, bytes):
stream_or_string = stream_or_string.decode()
if isinstance(stream_or_string, str):
stream = StringIO(stream_or_string)
else:
stream = stream_o... | [
"def",
"Deserializer",
"(",
"stream_or_string",
",",
"*",
"*",
"options",
")",
":",
"if",
"isinstance",
"(",
"stream_or_string",
",",
"bytes",
")",
":",
"stream_or_string",
"=",
"stream_or_string",
".",
"decode",
"(",
")",
"if",
"isinstance",
"(",
"stream_or_s... | [
66,
0
] | [
79,
45
] | python | en | ['en', 'en', 'en'] | True |
SessionStore.load | (self) |
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
|
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
| def load(self):
"""
We load the data from the key itself instead of fetching from
some external data store. Opposite of _get_session_key(),
raises BadSignature if signature fails.
"""
try:
return signing.loads(self.session_key,
serializer=self.... | [
"def",
"load",
"(",
"self",
")",
":",
"try",
":",
"return",
"signing",
".",
"loads",
"(",
"self",
".",
"session_key",
",",
"serializer",
"=",
"self",
".",
"serializer",
",",
"# This doesn't handle non-default expiry dates, see #19201",
"max_age",
"=",
"settings",
... | [
8,
4
] | [
22,
17
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.create | (self) |
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
|
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
| def create(self):
"""
To create a new key, we simply make sure that the modified flag is set
so that the cookie is set on the client for the current request.
"""
self.modified = True | [
"def",
"create",
"(",
"self",
")",
":",
"self",
".",
"modified",
"=",
"True"
] | [
24,
4
] | [
29,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.save | (self, must_create=False) |
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
|
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
| def save(self, must_create=False):
"""
To save, we get the session key as a securely signed string and then
set the modified flag so that the cookie is set on the client for the
current request.
"""
self._session_key = self._get_session_key()
self.modified = True | [
"def",
"save",
"(",
"self",
",",
"must_create",
"=",
"False",
")",
":",
"self",
".",
"_session_key",
"=",
"self",
".",
"_get_session_key",
"(",
")",
"self",
".",
"modified",
"=",
"True"
] | [
31,
4
] | [
38,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.exists | (self, session_key=None) |
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
|
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
| def exists(self, session_key=None):
"""
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
"""
return False | [
"def",
"exists",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"return",
"False"
] | [
40,
4
] | [
46,
20
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.delete | (self, session_key=None) |
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
|
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
| def delete(self, session_key=None):
"""
To delete, we clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
"""
self._session_key = ''
self._session_cache = {}
sel... | [
"def",
"delete",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"self",
".",
"_session_key",
"=",
"''",
"self",
".",
"_session_cache",
"=",
"{",
"}",
"self",
".",
"modified",
"=",
"True"
] | [
48,
4
] | [
56,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.cycle_key | (self) |
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
|
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
| def cycle_key(self):
"""
Keeps the same data but with a new key. To do this, we just have to
call ``save()`` and it will automatically save a cookie with a new key
at the end of the request.
"""
self.save() | [
"def",
"cycle_key",
"(",
"self",
")",
":",
"self",
".",
"save",
"(",
")"
] | [
58,
4
] | [
64,
19
] | python | en | ['en', 'error', 'th'] | False |
SessionStore._get_session_key | (self) |
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
|
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
| def _get_session_key(self):
"""
Most session backends don't need to override this method, but we do,
because instead of generating a random string, we want to actually
generate a secure url-safe Base64-encoded string of data as our
session key.
"""
session_cache =... | [
"def",
"_get_session_key",
"(",
"self",
")",
":",
"session_cache",
"=",
"getattr",
"(",
"self",
",",
"'_session_cache'",
",",
"{",
"}",
")",
"return",
"signing",
".",
"dumps",
"(",
"session_cache",
",",
"compress",
"=",
"True",
",",
"salt",
"=",
"'django.c... | [
66,
4
] | [
76,
39
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.test_ticket_creation | (self) |
Messages are generated on ticket creation through Freshdesk's
"Dispatch'r" service.
|
Messages are generated on ticket creation through Freshdesk's
"Dispatch'r" service.
| def test_ticket_creation(self) -> None:
"""
Messages are generated on ticket creation through Freshdesk's
"Dispatch'r" service.
"""
expected_topic = "#11: Test ticket subject ☃"
expected_message = """
Requester ☃ Bob <requester-bob@example.com> created [ticket #11](http:/... | [
"def",
"test_ticket_creation",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"#11: Test ticket subject ☃\"",
"expected_message",
"=",
"\"\"\"\nRequester ☃ Bob <requester-bob@example.com> created [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):\n\n``` quot... | [
10,
4
] | [
34,
9
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.test_status_change | (self) |
Messages are generated when a ticket's status changes through
Freshdesk's "Observer" service.
|
Messages are generated when a ticket's status changes through
Freshdesk's "Observer" service.
| def test_status_change(self) -> None:
"""
Messages are generated when a ticket's status changes through
Freshdesk's "Observer" service.
"""
expected_topic = "#11: Test ticket subject ☃"
expected_message = """
Requester Bob <requester-bob@example.com> updated [ticket #11](... | [
"def",
"test_status_change",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"#11: Test ticket subject ☃\"",
"expected_message",
"=",
"\"\"\"\nRequester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):\n\n* **Status**... | [
36,
4
] | [
54,
9
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.test_priority_change | (self) |
Messages are generated when a ticket's priority changes through
Freshdesk's "Observer" service.
|
Messages are generated when a ticket's priority changes through
Freshdesk's "Observer" service.
| def test_priority_change(self) -> None:
"""
Messages are generated when a ticket's priority changes through
Freshdesk's "Observer" service.
"""
expected_topic = "#11: Test ticket subject"
expected_message = """
Requester Bob <requester-bob@example.com> updated [ticket #11... | [
"def",
"test_priority_change",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"#11: Test ticket subject\"",
"expected_message",
"=",
"\"\"\"\nRequester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):\n\n* **Priority... | [
56,
4
] | [
73,
9
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.test_unknown_event_payload_ignore | (self, check_send_webhook_message_mock: MagicMock) |
Ignore unknown event payloads.
|
Ignore unknown event payloads.
| def test_unknown_event_payload_ignore(self, check_send_webhook_message_mock: MagicMock) -> None:
"""
Ignore unknown event payloads.
"""
self.url = self.build_webhook_url()
payload = self.get_body("unknown_payload")
kwargs = {
"HTTP_AUTHORIZATION": self.encode_... | [
"def",
"test_unknown_event_payload_ignore",
"(",
"self",
",",
"check_send_webhook_message_mock",
":",
"MagicMock",
")",
"->",
"None",
":",
"self",
".",
"url",
"=",
"self",
".",
"build_webhook_url",
"(",
")",
"payload",
"=",
"self",
".",
"get_body",
"(",
"\"unkno... | [
76,
4
] | [
88,
40
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.note_change | (self, fixture: str, note_type: str) |
Messages are generated when a note gets added to a ticket through
Freshdesk's "Observer" service.
|
Messages are generated when a note gets added to a ticket through
Freshdesk's "Observer" service.
| def note_change(self, fixture: str, note_type: str) -> None:
"""
Messages are generated when a note gets added to a ticket through
Freshdesk's "Observer" service.
"""
expected_topic = "#11: Test ticket subject"
expected_message = """
Requester Bob <requester-bob@example.c... | [
"def",
"note_change",
"(",
"self",
",",
"fixture",
":",
"str",
",",
"note_type",
":",
"str",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"#11: Test ticket subject\"",
"expected_message",
"=",
"\"\"\"\nRequester Bob <requester-bob@example.com> added a {} note to \\\n[ti... | [
90,
4
] | [
108,
9
] | python | en | ['en', 'error', 'th'] | False |
FreshdeskHookTests.test_inline_image | (self) |
Freshdesk sends us descriptions as HTML, so we have to make the
descriptions Zulip Markdown-friendly while still doing our best to
preserve links and images.
|
Freshdesk sends us descriptions as HTML, so we have to make the
descriptions Zulip Markdown-friendly while still doing our best to
preserve links and images.
| def test_inline_image(self) -> None:
"""
Freshdesk sends us descriptions as HTML, so we have to make the
descriptions Zulip Markdown-friendly while still doing our best to
preserve links and images.
"""
expected_topic = "#12: Not enough ☃ guinea pigs"
expected_mes... | [
"def",
"test_inline_image",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"#12: Not enough ☃ guinea pigs\"",
"expected_message",
"=",
"\"\"\"\nRequester \\u2603 Bob <requester-bob@example.com> created [ticket #12](http://test1234zzz.freshdesk.com/helpdesk/tickets/12):\\n\\n... | [
116,
4
] | [
132,
9
] | python | en | ['en', 'error', 'th'] | False |
CustomUserManager.create_user | (self, email, date_of_birth, password=None) |
Creates and saves a User with the given email and password.
|
Creates and saves a User with the given email and password.
| def create_user(self, email, date_of_birth, password=None):
"""
Creates and saves a User with the given email and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
... | [
"def",
"create_user",
"(",
"self",
",",
"email",
",",
"date_of_birth",
",",
"password",
"=",
"None",
")",
":",
"if",
"not",
"email",
":",
"raise",
"ValueError",
"(",
"'Users must have an email address'",
")",
"user",
"=",
"self",
".",
"model",
"(",
"email",
... | [
17,
4
] | [
31,
19
] | python | en | ['en', 'error', 'th'] | False |
IndexesTests.test_postgresql_text_indexes | (self) | Test creation of PostgreSQL-specific text indexes (#12234) | Test creation of PostgreSQL-specific text indexes (#12234) | def test_postgresql_text_indexes(self):
"""Test creation of PostgreSQL-specific text indexes (#12234)"""
from .models import IndexedArticle
index_sql = connection.creation.sql_indexes_for_model(IndexedArticle, no_style())
self.assertEqual(len(index_sql), 5)
self.assertIn('("headl... | [
"def",
"test_postgresql_text_indexes",
"(",
"self",
")",
":",
"from",
".",
"models",
"import",
"IndexedArticle",
"index_sql",
"=",
"connection",
".",
"creation",
".",
"sql_indexes_for_model",
"(",
"IndexedArticle",
",",
"no_style",
"(",
")",
")",
"self",
".",
"a... | [
21,
4
] | [
30,
67
] | python | en | ['en', 'de', 'en'] | True |
IndexesTests.test_postgresql_virtual_relation_indexes | (self) | Test indexes are not created for related objects | Test indexes are not created for related objects | def test_postgresql_virtual_relation_indexes(self):
"""Test indexes are not created for related objects"""
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
self.assertEqual(len(index_sql), 1) | [
"def",
"test_postgresql_virtual_relation_indexes",
"(",
"self",
")",
":",
"index_sql",
"=",
"connection",
".",
"creation",
".",
"sql_indexes_for_model",
"(",
"Article",
",",
"no_style",
"(",
")",
")",
"self",
".",
"assertEqual",
"(",
"len",
"(",
"index_sql",
")"... | [
34,
4
] | [
37,
43
] | python | en | ['en', 'en', 'en'] | True |
CustomRemoteUserBackend.clean_username | (self, username) |
Grabs username before the @ character.
|
Grabs username before the | def clean_username(self, username):
"""
Grabs username before the @ character.
"""
return username.split('@')[0] | [
"def",
"clean_username",
"(",
"self",
",",
"username",
")",
":",
"return",
"username",
".",
"split",
"(",
"'@'",
")",
"[",
"0",
"]"
] | [
177,
4
] | [
181,
37
] | python | en | ['en', 'error', 'th'] | False |
CustomRemoteUserBackend.configure_user | (self, user) |
Sets user's email address.
|
Sets user's email address.
| def configure_user(self, user):
"""
Sets user's email address.
"""
user.email = 'user@example.com'
user.save()
return user | [
"def",
"configure_user",
"(",
"self",
",",
"user",
")",
":",
"user",
".",
"email",
"=",
"'user@example.com'",
"user",
".",
"save",
"(",
")",
"return",
"user"
] | [
183,
4
] | [
189,
19
] | python | en | ['en', 'error', 'th'] | False |
Envelope.__init__ | (self, *args) |
The initialization function may take an OGREnvelope structure, 4-element
tuple or list, or 4 individual arguments.
|
The initialization function may take an OGREnvelope structure, 4-element
tuple or list, or 4 individual arguments.
| def __init__(self, *args):
"""
The initialization function may take an OGREnvelope structure, 4-element
tuple or list, or 4 individual arguments.
"""
if len(args) == 1:
if isinstance(args[0], OGREnvelope):
# OGREnvelope (a ctypes Structure) was passed... | [
"def",
"__init__",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"1",
":",
"if",
"isinstance",
"(",
"args",
"[",
"0",
"]",
",",
"OGREnvelope",
")",
":",
"# OGREnvelope (a ctypes Structure) was passed in.",
"self",
".",
"_e... | [
36,
4
] | [
65,
66
] | python | en | ['en', 'error', 'th'] | False |
Envelope.__eq__ | (self, other) |
Return True if the envelopes are equivalent; can compare against
other Envelopes and 4-tuples.
|
Return True if the envelopes are equivalent; can compare against
other Envelopes and 4-tuples.
| def __eq__(self, other):
"""
Return True if the envelopes are equivalent; can compare against
other Envelopes and 4-tuples.
"""
if isinstance(other, Envelope):
return (self.min_x == other.min_x) and (self.min_y == other.min_y) and \
(self.max_x == o... | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Envelope",
")",
":",
"return",
"(",
"self",
".",
"min_x",
"==",
"other",
".",
"min_x",
")",
"and",
"(",
"self",
".",
"min_y",
"==",
"other",
".",
"min_y",... | [
67,
4
] | [
79,
87
] | python | en | ['en', 'error', 'th'] | False |
Envelope.__str__ | (self) | Return a string representation of the tuple. | Return a string representation of the tuple. | def __str__(self):
"Return a string representation of the tuple."
return str(self.tuple) | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"str",
"(",
"self",
".",
"tuple",
")"
] | [
81,
4
] | [
83,
30
] | python | en | ['en', 'en', 'en'] | True |
Envelope._from_sequence | (self, seq) | Initialize the C OGR Envelope structure from the given sequence. | Initialize the C OGR Envelope structure from the given sequence. | def _from_sequence(self, seq):
"Initialize the C OGR Envelope structure from the given sequence."
self._envelope = OGREnvelope()
self._envelope.MinX = seq[0]
self._envelope.MinY = seq[1]
self._envelope.MaxX = seq[2]
self._envelope.MaxY = seq[3] | [
"def",
"_from_sequence",
"(",
"self",
",",
"seq",
")",
":",
"self",
".",
"_envelope",
"=",
"OGREnvelope",
"(",
")",
"self",
".",
"_envelope",
".",
"MinX",
"=",
"seq",
"[",
"0",
"]",
"self",
".",
"_envelope",
".",
"MinY",
"=",
"seq",
"[",
"1",
"]",
... | [
85,
4
] | [
91,
36
] | python | en | ['en', 'en', 'en'] | True |
Envelope.expand_to_include | (self, *args) |
Modify the envelope to expand to include the boundaries of
the passed-in 2-tuple (a point), 4-tuple (an extent) or
envelope.
|
Modify the envelope to expand to include the boundaries of
the passed-in 2-tuple (a point), 4-tuple (an extent) or
envelope.
| def expand_to_include(self, *args):
"""
Modify the envelope to expand to include the boundaries of
the passed-in 2-tuple (a point), 4-tuple (an extent) or
envelope.
"""
# We provide a number of different signatures for this method,
# and the logic here is all abou... | [
"def",
"expand_to_include",
"(",
"self",
",",
"*",
"args",
")",
":",
"# We provide a number of different signatures for this method,",
"# and the logic here is all about converting them into a",
"# 4-tuple single parameter which does the actual work of",
"# expanding the envelope.",
"if",
... | [
93,
4
] | [
133,
85
] | python | en | ['en', 'error', 'th'] | False |
Envelope.min_x | (self) | Return the value of the minimum X coordinate. | Return the value of the minimum X coordinate. | def min_x(self):
"Return the value of the minimum X coordinate."
return self._envelope.MinX | [
"def",
"min_x",
"(",
"self",
")",
":",
"return",
"self",
".",
"_envelope",
".",
"MinX"
] | [
136,
4
] | [
138,
34
] | python | en | ['en', 'la', 'en'] | True |
Envelope.min_y | (self) | Return the value of the minimum Y coordinate. | Return the value of the minimum Y coordinate. | def min_y(self):
"Return the value of the minimum Y coordinate."
return self._envelope.MinY | [
"def",
"min_y",
"(",
"self",
")",
":",
"return",
"self",
".",
"_envelope",
".",
"MinY"
] | [
141,
4
] | [
143,
34
] | python | en | ['en', 'la', 'en'] | True |
Envelope.max_x | (self) | Return the value of the maximum X coordinate. | Return the value of the maximum X coordinate. | def max_x(self):
"Return the value of the maximum X coordinate."
return self._envelope.MaxX | [
"def",
"max_x",
"(",
"self",
")",
":",
"return",
"self",
".",
"_envelope",
".",
"MaxX"
] | [
146,
4
] | [
148,
34
] | python | en | ['en', 'la', 'en'] | True |
Envelope.max_y | (self) | Return the value of the maximum Y coordinate. | Return the value of the maximum Y coordinate. | def max_y(self):
"Return the value of the maximum Y coordinate."
return self._envelope.MaxY | [
"def",
"max_y",
"(",
"self",
")",
":",
"return",
"self",
".",
"_envelope",
".",
"MaxY"
] | [
151,
4
] | [
153,
34
] | python | en | ['en', 'la', 'en'] | True |
Envelope.ur | (self) | Return the upper-right coordinate. | Return the upper-right coordinate. | def ur(self):
"Return the upper-right coordinate."
return (self.max_x, self.max_y) | [
"def",
"ur",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"max_x",
",",
"self",
".",
"max_y",
")"
] | [
156,
4
] | [
158,
39
] | python | en | ['en', 'en', 'en'] | True |
Envelope.ll | (self) | Return the lower-left coordinate. | Return the lower-left coordinate. | def ll(self):
"Return the lower-left coordinate."
return (self.min_x, self.min_y) | [
"def",
"ll",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"min_x",
",",
"self",
".",
"min_y",
")"
] | [
161,
4
] | [
163,
39
] | python | en | ['en', 'en', 'en'] | True |
Envelope.tuple | (self) | Return a tuple representing the envelope. | Return a tuple representing the envelope. | def tuple(self):
"Return a tuple representing the envelope."
return (self.min_x, self.min_y, self.max_x, self.max_y) | [
"def",
"tuple",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"min_x",
",",
"self",
".",
"min_y",
",",
"self",
".",
"max_x",
",",
"self",
".",
"max_y",
")"
] | [
166,
4
] | [
168,
63
] | python | en | ['en', 'en', 'en'] | True |
Envelope.wkt | (self) | Return WKT representing a Polygon for this envelope. | Return WKT representing a Polygon for this envelope. | def wkt(self):
"Return WKT representing a Polygon for this envelope."
# TODO: Fix significant figures.
return 'POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s))' % \
(self.min_x, self.min_y, self.min_x, self.max_y,
self.max_x, self.max_y, self.max_x, self.min_y,
... | [
"def",
"wkt",
"(",
"self",
")",
":",
"# TODO: Fix significant figures.",
"return",
"'POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s))'",
"%",
"(",
"self",
".",
"min_x",
",",
"self",
".",
"min_y",
",",
"self",
".",
"min_x",
",",
"self",
".",
"max_y",
",",
"self",
".",
... | [
171,
4
] | [
177,
39
] | python | en | ['en', 'en', 'en'] | True |
split_first | (s, delims) |
.. deprecated:: 1.25
Given a string and an iterable of delimiters, split on the first found
delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz', '?/=')
('foo', 'bar?baz',... |
.. deprecated:: 1.25 | def split_first(s, delims):
"""
.. deprecated:: 1.25
Given a string and an iterable of delimiters, split on the first found
delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz'... | [
"def",
"split_first",
"(",
"s",
",",
"delims",
")",
":",
"min_idx",
"=",
"None",
"min_delim",
"=",
"None",
"for",
"d",
"in",
"delims",
":",
"idx",
"=",
"s",
".",
"find",
"(",
"d",
")",
"if",
"idx",
"<",
"0",
":",
"continue",
"if",
"min_idx",
"is"... | [
174,
0
] | [
206,
51
] | python | en | ['en', 'error', 'th'] | False |
_encode_invalid_chars | (component, allowed_chars, encoding="utf-8") | Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
| Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
| def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
"""Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
"""
if component is None:
return component
component = six.ensure_text(component)
# Normalize existing percent-encoded... | [
"def",
"_encode_invalid_chars",
"(",
"component",
",",
"allowed_chars",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"if",
"component",
"is",
"None",
":",
"return",
"component",
"component",
"=",
"six",
".",
"ensure_text",
"(",
"component",
")",
"# Normalize exi... | [
209,
0
] | [
240,
45
] | python | en | ['en', 'en', 'en'] | True |
_encode_target | (target) | Percent-encodes a request target so that there are no invalid characters | Percent-encodes a request target so that there are no invalid characters | def _encode_target(target):
"""Percent-encodes a request target so that there are no invalid characters"""
path, query = TARGET_RE.match(target).groups()
target = _encode_invalid_chars(path, PATH_CHARS)
query = _encode_invalid_chars(query, QUERY_CHARS)
if query is not None:
target += "?" + q... | [
"def",
"_encode_target",
"(",
"target",
")",
":",
"path",
",",
"query",
"=",
"TARGET_RE",
".",
"match",
"(",
"target",
")",
".",
"groups",
"(",
")",
"target",
"=",
"_encode_invalid_chars",
"(",
"path",
",",
"PATH_CHARS",
")",
"query",
"=",
"_encode_invalid... | [
319,
0
] | [
326,
17
] | python | en | ['en', 'en', 'en'] | True |
parse_url | (url) |
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant.
The parser logic and helper functions are based heavily on
work done in the ``rfc3986`` module.
:param str url: URL to... |
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant. | def parse_url(url):
"""
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant.
The parser logic and helper functions are based heavily on
work done in the ``rfc3986`` module.
... | [
"def",
"parse_url",
"(",
"url",
")",
":",
"if",
"not",
"url",
":",
"# Empty",
"return",
"Url",
"(",
")",
"source_url",
"=",
"url",
"if",
"not",
"SCHEME_RE",
".",
"search",
"(",
"url",
")",
":",
"url",
"=",
"\"//\"",
"+",
"url",
"try",
":",
"scheme"... | [
329,
0
] | [
421,
5
] | python | en | ['en', 'error', 'th'] | False |
get_host | (url) |
Deprecated. Use :func:`parse_url` instead.
|
Deprecated. Use :func:`parse_url` instead.
| def get_host(url):
"""
Deprecated. Use :func:`parse_url` instead.
"""
p = parse_url(url)
return p.scheme or "http", p.hostname, p.port | [
"def",
"get_host",
"(",
"url",
")",
":",
"p",
"=",
"parse_url",
"(",
"url",
")",
"return",
"p",
".",
"scheme",
"or",
"\"http\"",
",",
"p",
".",
"hostname",
",",
"p",
".",
"port"
] | [
424,
0
] | [
429,
49
] | python | en | ['en', 'error', 'th'] | False |
Url.hostname | (self) | For backwards-compatibility with urlparse. We're nice like that. | For backwards-compatibility with urlparse. We're nice like that. | def hostname(self):
"""For backwards-compatibility with urlparse. We're nice like that."""
return self.host | [
"def",
"hostname",
"(",
"self",
")",
":",
"return",
"self",
".",
"host"
] | [
109,
4
] | [
111,
24
] | python | en | ['en', 'en', 'en'] | True |
Url.request_uri | (self) | Absolute path including the query string. | Absolute path including the query string. | def request_uri(self):
"""Absolute path including the query string."""
uri = self.path or "/"
if self.query is not None:
uri += "?" + self.query
return uri | [
"def",
"request_uri",
"(",
"self",
")",
":",
"uri",
"=",
"self",
".",
"path",
"or",
"\"/\"",
"if",
"self",
".",
"query",
"is",
"not",
"None",
":",
"uri",
"+=",
"\"?\"",
"+",
"self",
".",
"query",
"return",
"uri"
] | [
114,
4
] | [
121,
18
] | python | en | ['en', 'en', 'en'] | True |
Url.netloc | (self) | Network location including host and port | Network location including host and port | def netloc(self):
"""Network location including host and port"""
if self.port:
return "%s:%d" % (self.host, self.port)
return self.host | [
"def",
"netloc",
"(",
"self",
")",
":",
"if",
"self",
".",
"port",
":",
"return",
"\"%s:%d\"",
"%",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
")",
"return",
"self",
".",
"host"
] | [
124,
4
] | [
128,
24
] | python | en | ['en', 'en', 'en'] | True |
Url.url | (self) |
Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The
returned url may not be exactly the same as the url inputted to
:func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
with a blank port will have : removed).
... |
Convert self into a url | def url(self):
"""
Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The
returned url may not be exactly the same as the url inputted to
:func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
with a blank port w... | [
"def",
"url",
"(",
"self",
")",
":",
"scheme",
",",
"auth",
",",
"host",
",",
"port",
",",
"path",
",",
"query",
",",
"fragment",
"=",
"self",
"url",
"=",
"u\"\"",
"# We use \"is not None\" we want things to happen with empty strings (or 0 port)",
"if",
"scheme",
... | [
131,
4
] | [
168,
18
] | python | en | ['en', 'error', 'th'] | False |
BasicFieldTests.test_show_hidden_initial | (self) |
Regression test for #12913. Make sure fields with choices respect
show_hidden_initial as a kwarg to models.Field.formfield()
|
Regression test for #12913. Make sure fields with choices respect
show_hidden_initial as a kwarg to models.Field.formfield()
| def test_show_hidden_initial(self):
"""
Regression test for #12913. Make sure fields with choices respect
show_hidden_initial as a kwarg to models.Field.formfield()
"""
choices = [(0, 0), (1, 1)]
model_field = models.Field(choices=choices)
form_field = model_field... | [
"def",
"test_show_hidden_initial",
"(",
"self",
")",
":",
"choices",
"=",
"[",
"(",
"0",
",",
"0",
")",
",",
"(",
"1",
",",
"1",
")",
"]",
"model_field",
"=",
"models",
".",
"Field",
"(",
"choices",
"=",
"choices",
")",
"form_field",
"=",
"model_fiel... | [
32,
4
] | [
43,
56
] | python | en | ['en', 'error', 'th'] | False |
BasicFieldTests.test_nullbooleanfield_blank | (self) |
Regression test for #13071: NullBooleanField should not throw
a validation error when given a value of None.
|
Regression test for #13071: NullBooleanField should not throw
a validation error when given a value of None. | def test_nullbooleanfield_blank(self):
"""
Regression test for #13071: NullBooleanField should not throw
a validation error when given a value of None.
"""
nullboolean = NullBooleanModel(nbfield=None)
try:
nullboolean.full_clean()
except ValidationErr... | [
"def",
"test_nullbooleanfield_blank",
"(",
"self",
")",
":",
"nullboolean",
"=",
"NullBooleanModel",
"(",
"nbfield",
"=",
"None",
")",
"try",
":",
"nullboolean",
".",
"full_clean",
"(",
")",
"except",
"ValidationError",
"as",
"e",
":",
"self",
".",
"fail",
"... | [
45,
4
] | [
55,
95
] | python | en | ['en', 'error', 'th'] | False |
BasicFieldTests.test_field_repr | (self) |
Regression test for #5931: __repr__ of a field also displays its name
|
Regression test for #5931: __repr__ of a field also displays its name
| def test_field_repr(self):
"""
Regression test for #5931: __repr__ of a field also displays its name
"""
f = Foo._meta.get_field('a')
self.assertEqual(repr(f), '<django.db.models.fields.CharField: a>')
f = models.fields.CharField()
self.assertEqual(repr(f), '<djan... | [
"def",
"test_field_repr",
"(",
"self",
")",
":",
"f",
"=",
"Foo",
".",
"_meta",
".",
"get_field",
"(",
"'a'",
")",
"self",
".",
"assertEqual",
"(",
"repr",
"(",
"f",
")",
",",
"'<django.db.models.fields.CharField: a>'",
")",
"f",
"=",
"models",
".",
"fie... | [
57,
4
] | [
64,
72
] | python | en | ['en', 'error', 'th'] | False |
BasicFieldTests.test_field_name | (self) |
Regression test for #14695: explicitly defined field name overwritten
by model's attribute name.
|
Regression test for #14695: explicitly defined field name overwritten
by model's attribute name.
| def test_field_name(self):
"""
Regression test for #14695: explicitly defined field name overwritten
by model's attribute name.
"""
instance = RenamedField()
self.assertTrue(hasattr(instance, 'get_fieldname_display'))
self.assertFalse(hasattr(instance, 'get_modeln... | [
"def",
"test_field_name",
"(",
"self",
")",
":",
"instance",
"=",
"RenamedField",
"(",
")",
"self",
".",
"assertTrue",
"(",
"hasattr",
"(",
"instance",
",",
"'get_fieldname_display'",
")",
")",
"self",
".",
"assertFalse",
"(",
"hasattr",
"(",
"instance",
","... | [
66,
4
] | [
73,
68
] | python | en | ['en', 'error', 'th'] | False |
BasicFieldTests.test_choices_form_class | (self) | Can supply a custom choices form class. Regression for #20999. | Can supply a custom choices form class. Regression for #20999. | def test_choices_form_class(self):
"""Can supply a custom choices form class. Regression for #20999."""
choices = [('a', 'a')]
field = models.CharField(choices=choices)
klass = forms.TypedMultipleChoiceField
self.assertIsInstance(field.formfield(choices_form_class=klass), klass) | [
"def",
"test_choices_form_class",
"(",
"self",
")",
":",
"choices",
"=",
"[",
"(",
"'a'",
",",
"'a'",
")",
"]",
"field",
"=",
"models",
".",
"CharField",
"(",
"choices",
"=",
"choices",
")",
"klass",
"=",
"forms",
".",
"TypedMultipleChoiceField",
"self",
... | [
105,
4
] | [
110,
79
] | python | en | ['en', 'en', 'en'] | True |
DecimalFieldTests.test_filter_with_strings | (self) |
We should be able to filter decimal fields using strings (#8023)
|
We should be able to filter decimal fields using strings (#8023)
| def test_filter_with_strings(self):
"""
We should be able to filter decimal fields using strings (#8023)
"""
Foo.objects.create(id=1, a='abc', d=Decimal("12.34"))
self.assertEqual(list(Foo.objects.filter(d='1.23')), []) | [
"def",
"test_filter_with_strings",
"(",
"self",
")",
":",
"Foo",
".",
"objects",
".",
"create",
"(",
"id",
"=",
"1",
",",
"a",
"=",
"'abc'",
",",
"d",
"=",
"Decimal",
"(",
"\"12.34\"",
")",
")",
"self",
".",
"assertEqual",
"(",
"list",
"(",
"Foo",
... | [
139,
4
] | [
144,
64
] | python | en | ['en', 'error', 'th'] | False |
DecimalFieldTests.test_save_without_float_conversion | (self) |
Ensure decimals don't go through a corrupting float conversion during
save (#5079).
|
Ensure decimals don't go through a corrupting float conversion during
save (#5079).
| def test_save_without_float_conversion(self):
"""
Ensure decimals don't go through a corrupting float conversion during
save (#5079).
"""
bd = BigD(d="12.9")
bd.save()
bd = BigD.objects.get(pk=bd.pk)
self.assertEqual(bd.d, Decimal("12.9")) | [
"def",
"test_save_without_float_conversion",
"(",
"self",
")",
":",
"bd",
"=",
"BigD",
"(",
"d",
"=",
"\"12.9\"",
")",
"bd",
".",
"save",
"(",
")",
"bd",
"=",
"BigD",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"bd",
".",
"pk",
")",
"self",
".",
... | [
146,
4
] | [
154,
47
] | python | en | ['en', 'error', 'th'] | False |
DecimalFieldTests.test_lookup_really_big_value | (self) |
Ensure that really big values can be used in a filter statement, even
with older Python versions.
|
Ensure that really big values can be used in a filter statement, even
with older Python versions.
| def test_lookup_really_big_value(self):
"""
Ensure that really big values can be used in a filter statement, even
with older Python versions.
"""
# This should not crash. That counts as a win for our purposes.
Foo.objects.filter(d__gte=100000000000) | [
"def",
"test_lookup_really_big_value",
"(",
"self",
")",
":",
"# This should not crash. That counts as a win for our purposes.",
"Foo",
".",
"objects",
".",
"filter",
"(",
"d__gte",
"=",
"100000000000",
")"
] | [
156,
4
] | [
162,
47
] | python | en | ['en', 'error', 'th'] | False |
ForeignKeyTests.test_callable_default | (self) | Test the use of a lazy callable for ForeignKey.default | Test the use of a lazy callable for ForeignKey.default | def test_callable_default(self):
"""Test the use of a lazy callable for ForeignKey.default"""
a = Foo.objects.create(id=1, a='abc', d=Decimal("12.34"))
b = Bar.objects.create(b="bcd")
self.assertEqual(b.a, a) | [
"def",
"test_callable_default",
"(",
"self",
")",
":",
"a",
"=",
"Foo",
".",
"objects",
".",
"create",
"(",
"id",
"=",
"1",
",",
"a",
"=",
"'abc'",
",",
"d",
"=",
"Decimal",
"(",
"\"12.34\"",
")",
")",
"b",
"=",
"Bar",
".",
"objects",
".",
"creat... | [
166,
4
] | [
170,
32
] | python | en | ['en', 'en', 'en'] | True |
ForeignKeyTests.test_empty_string_fk | (self) |
Test that foreign key values to empty strings don't get converted
to None (#19299)
|
Test that foreign key values to empty strings don't get converted
to None (#19299)
| def test_empty_string_fk(self):
"""
Test that foreign key values to empty strings don't get converted
to None (#19299)
"""
char_model_empty = PrimaryKeyCharModel.objects.create(string='')
fk_model_empty = FkToChar.objects.create(out=char_model_empty)
fk_model_empt... | [
"def",
"test_empty_string_fk",
"(",
"self",
")",
":",
"char_model_empty",
"=",
"PrimaryKeyCharModel",
".",
"objects",
".",
"create",
"(",
"string",
"=",
"''",
")",
"fk_model_empty",
"=",
"FkToChar",
".",
"objects",
".",
"create",
"(",
"out",
"=",
"char_model_e... | [
173,
4
] | [
181,
62
] | python | en | ['en', 'error', 'th'] | False |
DateTimeFieldTests.test_datetimefield_to_python_usecs | (self) | DateTimeField.to_python should support usecs | DateTimeField.to_python should support usecs | def test_datetimefield_to_python_usecs(self):
"""DateTimeField.to_python should support usecs"""
f = models.DateTimeField()
self.assertEqual(f.to_python('2001-01-02 03:04:05.000006'),
datetime.datetime(2001, 1, 2, 3, 4, 5, 6))
self.assertEqual(f.to_python('2001-0... | [
"def",
"test_datetimefield_to_python_usecs",
"(",
"self",
")",
":",
"f",
"=",
"models",
".",
"DateTimeField",
"(",
")",
"self",
".",
"assertEqual",
"(",
"f",
".",
"to_python",
"(",
"'2001-01-02 03:04:05.000006'",
")",
",",
"datetime",
".",
"datetime",
"(",
"20... | [
185,
4
] | [
191,
72
] | python | en | ['en', 'en', 'en'] | True |
DateTimeFieldTests.test_timefield_to_python_usecs | (self) | TimeField.to_python should support usecs | TimeField.to_python should support usecs | def test_timefield_to_python_usecs(self):
"""TimeField.to_python should support usecs"""
f = models.TimeField()
self.assertEqual(f.to_python('01:02:03.000004'),
datetime.time(1, 2, 3, 4))
self.assertEqual(f.to_python('01:02:03.999999'),
d... | [
"def",
"test_timefield_to_python_usecs",
"(",
"self",
")",
":",
"f",
"=",
"models",
".",
"TimeField",
"(",
")",
"self",
".",
"assertEqual",
"(",
"f",
".",
"to_python",
"(",
"'01:02:03.000004'",
")",
",",
"datetime",
".",
"time",
"(",
"1",
",",
"2",
",",
... | [
193,
4
] | [
199,
56
] | python | en | ['en', 'en', 'en'] | True |
BooleanFieldTests.test_charfield_textfield_max_length_passed_to_formfield | (self) |
Test that CharField and TextField pass their max_length attributes to
form fields created using their .formfield() method (#22206).
|
Test that CharField and TextField pass their max_length attributes to
form fields created using their .formfield() method (#22206).
| def test_charfield_textfield_max_length_passed_to_formfield(self):
"""
Test that CharField and TextField pass their max_length attributes to
form fields created using their .formfield() method (#22206).
"""
cf1 = models.CharField()
cf2 = models.CharField(max_length=1234)
... | [
"def",
"test_charfield_textfield_max_length_passed_to_formfield",
"(",
"self",
")",
":",
"cf1",
"=",
"models",
".",
"CharField",
"(",
")",
"cf2",
"=",
"models",
".",
"CharField",
"(",
"max_length",
"=",
"1234",
")",
"self",
".",
"assertIsNone",
"(",
"cf1",
"."... | [
240,
4
] | [
253,
58
] | python | en | ['en', 'error', 'th'] | False |
BooleanFieldTests.test_booleanfield_choices_blank | (self) |
Test that BooleanField with choices and defaults doesn't generate a
formfield with the blank option (#9640, #10549).
|
Test that BooleanField with choices and defaults doesn't generate a
formfield with the blank option (#9640, #10549).
| def test_booleanfield_choices_blank(self):
"""
Test that BooleanField with choices and defaults doesn't generate a
formfield with the blank option (#9640, #10549).
"""
choices = [(1, 'Si'), (2, 'No')]
f = models.BooleanField(choices=choices, default=1, null=False)
... | [
"def",
"test_booleanfield_choices_blank",
"(",
"self",
")",
":",
"choices",
"=",
"[",
"(",
"1",
",",
"'Si'",
")",
",",
"(",
"2",
",",
"'No'",
")",
"]",
"f",
"=",
"models",
".",
"BooleanField",
"(",
"choices",
"=",
"choices",
",",
"default",
"=",
"1",... | [
255,
4
] | [
262,
56
] | python | en | ['en', 'error', 'th'] | False |
BooleanFieldTests.test_select_related | (self) |
Test type of boolean fields when retrieved via select_related() (MySQL,
#15040)
|
Test type of boolean fields when retrieved via select_related() (MySQL,
#15040)
| def test_select_related(self):
"""
Test type of boolean fields when retrieved via select_related() (MySQL,
#15040)
"""
bmt = BooleanModel.objects.create(bfield=True)
bmf = BooleanModel.objects.create(bfield=False)
nbmt = NullBooleanModel.objects.create(nbfield=Tru... | [
"def",
"test_select_related",
"(",
"self",
")",
":",
"bmt",
"=",
"BooleanModel",
".",
"objects",
".",
"create",
"(",
"bfield",
"=",
"True",
")",
"bmf",
"=",
"BooleanModel",
".",
"objects",
".",
"create",
"(",
"bfield",
"=",
"False",
")",
"nbmt",
"=",
"... | [
300,
4
] | [
334,
47
] | python | en | ['en', 'error', 'th'] | False |
BooleanFieldTests.test_null_default | (self) |
Check that a BooleanField defaults to None -- which isn't
a valid value (#15124).
|
Check that a BooleanField defaults to None -- which isn't
a valid value (#15124).
| def test_null_default(self):
"""
Check that a BooleanField defaults to None -- which isn't
a valid value (#15124).
"""
# Patch the boolean field's default value. We give it a default
# value when defining the model to satisfy the check tests
# #20895.
bool... | [
"def",
"test_null_default",
"(",
"self",
")",
":",
"# Patch the boolean field's default value. We give it a default",
"# value when defining the model to satisfy the check tests",
"# #20895.",
"boolean_field",
"=",
"BooleanModel",
".",
"_meta",
".",
"get_field",
"(",
"'bfield'",
... | [
336,
4
] | [
360,
17
] | python | en | ['en', 'error', 'th'] | False |
ChoicesTests.test_choices_and_field_display | (self) |
Check that get_choices and get_flatchoices interact with
get_FIELD_display to return the expected values (#7913).
|
Check that get_choices and get_flatchoices interact with
get_FIELD_display to return the expected values (#7913).
| def test_choices_and_field_display(self):
"""
Check that get_choices and get_flatchoices interact with
get_FIELD_display to return the expected values (#7913).
"""
self.assertEqual(Whiz(c=1).get_c_display(), 'First') # A nested value
self.assertEqual(Whiz(c=0).get_c_di... | [
"def",
"test_choices_and_field_display",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Whiz",
"(",
"c",
"=",
"1",
")",
".",
"get_c_display",
"(",
")",
",",
"'First'",
")",
"# A nested value",
"self",
".",
"assertEqual",
"(",
"Whiz",
"(",
"c",
... | [
364,
4
] | [
373,
56
] | python | en | ['en', 'error', 'th'] | False |
ChoicesTests.test_iterator_choices | (self) |
Check that get_choices works with Iterators (#23112).
|
Check that get_choices works with Iterators (#23112).
| def test_iterator_choices(self):
"""
Check that get_choices works with Iterators (#23112).
"""
self.assertEqual(WhizIter(c=1).c, 1) # A nested value
self.assertEqual(WhizIter(c=9).c, 9) # Invalid value
self.assertEqual(WhizIter(c=None).c, None) # Blan... | [
"def",
"test_iterator_choices",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"WhizIter",
"(",
"c",
"=",
"1",
")",
".",
"c",
",",
"1",
")",
"# A nested value",
"self",
".",
"assertEqual",
"(",
"WhizIter",
"(",
"c",
"=",
"9",
")",
".",
"c",
... | [
375,
4
] | [
382,
46
] | python | en | ['en', 'error', 'th'] | False |
ChoicesTests.test_empty_iterator_choices | (self) |
Check that get_choices works with empty iterators (#23112).
|
Check that get_choices works with empty iterators (#23112).
| def test_empty_iterator_choices(self):
"""
Check that get_choices works with empty iterators (#23112).
"""
self.assertEqual(WhizIterEmpty(c="a").c, "a") # A nested value
self.assertEqual(WhizIterEmpty(c="b").c, "b") # Invalid value
self.assertEqual(WhizIterEmpty... | [
"def",
"test_empty_iterator_choices",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"WhizIterEmpty",
"(",
"c",
"=",
"\"a\"",
")",
".",
"c",
",",
"\"a\"",
")",
"# A nested value",
"self",
".",
"assertEqual",
"(",
"WhizIterEmpty",
"(",
"c",
"=",
"\... | [
384,
4
] | [
391,
51
] | python | en | ['en', 'error', 'th'] | False |
ChoicesTests.test_charfield_get_choices_with_blank_iterator | (self) |
Check that get_choices works with an empty Iterator
|
Check that get_choices works with an empty Iterator
| def test_charfield_get_choices_with_blank_iterator(self):
"""
Check that get_choices works with an empty Iterator
"""
f = models.CharField(choices=(x for x in []))
self.assertEqual(f.get_choices(include_blank=True), [('', '---------')]) | [
"def",
"test_charfield_get_choices_with_blank_iterator",
"(",
"self",
")",
":",
"f",
"=",
"models",
".",
"CharField",
"(",
"choices",
"=",
"(",
"x",
"for",
"x",
"in",
"[",
"]",
")",
")",
"self",
".",
"assertEqual",
"(",
"f",
".",
"get_choices",
"(",
"inc... | [
393,
4
] | [
398,
80
] | python | en | ['en', 'error', 'th'] | False |
SlugFieldTests.test_slugfield_max_length | (self) |
Make sure SlugField honors max_length (#9706)
|
Make sure SlugField honors max_length (#9706)
| def test_slugfield_max_length(self):
"""
Make sure SlugField honors max_length (#9706)
"""
bs = BigS.objects.create(s='slug' * 50)
bs = BigS.objects.get(pk=bs.pk)
self.assertEqual(bs.s, 'slug' * 50) | [
"def",
"test_slugfield_max_length",
"(",
"self",
")",
":",
"bs",
"=",
"BigS",
".",
"objects",
".",
"create",
"(",
"s",
"=",
"'slug'",
"*",
"50",
")",
"bs",
"=",
"BigS",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"bs",
".",
"pk",
")",
"self",
"."... | [
402,
4
] | [
408,
43
] | python | en | ['en', 'error', 'th'] | False |
IntegerFieldTests.test_documented_range | (self) |
Ensure that values within the documented safe range pass validation,
can be saved and retrieved without corruption.
|
Ensure that values within the documented safe range pass validation,
can be saved and retrieved without corruption.
| def test_documented_range(self):
"""
Ensure that values within the documented safe range pass validation,
can be saved and retrieved without corruption.
"""
min_value, max_value = self.documented_range
instance = self.model(value=min_value)
instance.full_clean()
... | [
"def",
"test_documented_range",
"(",
"self",
")",
":",
"min_value",
",",
"max_value",
"=",
"self",
".",
"documented_range",
"instance",
"=",
"self",
".",
"model",
"(",
"value",
"=",
"min_value",
")",
"instance",
".",
"full_clean",
"(",
")",
"instance",
".",
... | [
487,
4
] | [
506,
48
] | python | en | ['en', 'error', 'th'] | False |
IntegerFieldTests.test_backend_range_validation | (self) |
Ensure that backend specific range are enforced at the model
validation level. ref #12030.
|
Ensure that backend specific range are enforced at the model
validation level. ref #12030.
| def test_backend_range_validation(self):
"""
Ensure that backend specific range are enforced at the model
validation level. ref #12030.
"""
field = self.model._meta.get_field('value')
internal_type = field.get_internal_type()
min_value, max_value = connection.ops.... | [
"def",
"test_backend_range_validation",
"(",
"self",
")",
":",
"field",
"=",
"self",
".",
"model",
".",
"_meta",
".",
"get_field",
"(",
"'value'",
")",
"internal_type",
"=",
"field",
".",
"get_internal_type",
"(",
")",
"min_value",
",",
"max_value",
"=",
"co... | [
508,
4
] | [
535,
33
] | python | en | ['en', 'error', 'th'] | False |
FileFieldTests.test_clearable | (self) |
Test that FileField.save_form_data will clear its instance attribute
value if passed False.
|
Test that FileField.save_form_data will clear its instance attribute
value if passed False. | def test_clearable(self):
"""
Test that FileField.save_form_data will clear its instance attribute
value if passed False.
"""
d = Document(myfile='something.txt')
self.assertEqual(d.myfile, 'something.txt')
field = d._meta.get_field('myfile')
field.save_f... | [
"def",
"test_clearable",
"(",
"self",
")",
":",
"d",
"=",
"Document",
"(",
"myfile",
"=",
"'something.txt'",
")",
"self",
".",
"assertEqual",
"(",
"d",
".",
"myfile",
",",
"'something.txt'",
")",
"field",
"=",
"d",
".",
"_meta",
".",
"get_field",
"(",
... | [
586,
4
] | [
596,
38
] | python | en | ['en', 'error', 'th'] | False |
FileFieldTests.test_unchanged | (self) |
Test that FileField.save_form_data considers None to mean "no change"
rather than "clear".
|
Test that FileField.save_form_data considers None to mean "no change"
rather than "clear". | def test_unchanged(self):
"""
Test that FileField.save_form_data considers None to mean "no change"
rather than "clear".
"""
d = Document(myfile='something.txt')
self.assertEqual(d.myfile, 'something.txt')
field = d._meta.get_field('myfile')
field.save_fo... | [
"def",
"test_unchanged",
"(",
"self",
")",
":",
"d",
"=",
"Document",
"(",
"myfile",
"=",
"'something.txt'",
")",
"self",
".",
"assertEqual",
"(",
"d",
".",
"myfile",
",",
"'something.txt'",
")",
"field",
"=",
"d",
".",
"_meta",
".",
"get_field",
"(",
... | [
598,
4
] | [
608,
51
] | python | en | ['en', 'error', 'th'] | False |
FileFieldTests.test_changed | (self) |
Test that FileField.save_form_data, if passed a truthy value, updates
its instance attribute.
|
Test that FileField.save_form_data, if passed a truthy value, updates
its instance attribute. | def test_changed(self):
"""
Test that FileField.save_form_data, if passed a truthy value, updates
its instance attribute.
"""
d = Document(myfile='something.txt')
self.assertEqual(d.myfile, 'something.txt')
field = d._meta.get_field('myfile')
field.save_f... | [
"def",
"test_changed",
"(",
"self",
")",
":",
"d",
"=",
"Document",
"(",
"myfile",
"=",
"'something.txt'",
")",
"self",
".",
"assertEqual",
"(",
"d",
".",
"myfile",
",",
"'something.txt'",
")",
"field",
"=",
"d",
".",
"_meta",
".",
"get_field",
"(",
"'... | [
610,
4
] | [
620,
46
] | python | en | ['en', 'error', 'th'] | False |
FileFieldTests.test_delete_when_file_unset | (self) |
Calling delete on an unset FileField should not call the file deletion
process, but fail silently (#20660).
|
Calling delete on an unset FileField should not call the file deletion
process, but fail silently (#20660).
| def test_delete_when_file_unset(self):
"""
Calling delete on an unset FileField should not call the file deletion
process, but fail silently (#20660).
"""
d = Document()
try:
d.myfile.delete()
except OSError:
self.fail("Deleting an unset Fi... | [
"def",
"test_delete_when_file_unset",
"(",
"self",
")",
":",
"d",
"=",
"Document",
"(",
")",
"try",
":",
"d",
".",
"myfile",
".",
"delete",
"(",
")",
"except",
"OSError",
":",
"self",
".",
"fail",
"(",
"\"Deleting an unset FileField should not raise OSError.\"",... | [
622,
4
] | [
631,
78
] | python | en | ['en', 'error', 'th'] | False |
GenericIPAddressFieldTests.test_genericipaddressfield_formfield_protocol | (self) |
Test that GenericIPAddressField with a specified protocol does not
generate a formfield with no specified protocol. See #20740.
|
Test that GenericIPAddressField with a specified protocol does not
generate a formfield with no specified protocol. See #20740.
| def test_genericipaddressfield_formfield_protocol(self):
"""
Test that GenericIPAddressField with a specified protocol does not
generate a formfield with no specified protocol. See #20740.
"""
model_field = models.GenericIPAddressField(protocol='IPv4')
form_field = model_... | [
"def",
"test_genericipaddressfield_formfield_protocol",
"(",
"self",
")",
":",
"model_field",
"=",
"models",
".",
"GenericIPAddressField",
"(",
"protocol",
"=",
"'IPv4'",
")",
"form_field",
"=",
"model_field",
".",
"formfield",
"(",
")",
"self",
".",
"assertRaises",... | [
658,
4
] | [
668,
73
] | python | en | ['en', 'error', 'th'] | False |
CustomFieldTests.test_14786 | (self) |
Regression test for #14786 -- Test that field values are not prepared
twice in get_db_prep_lookup().
|
Regression test for #14786 -- Test that field values are not prepared
twice in get_db_prep_lookup().
| def test_14786(self):
"""
Regression test for #14786 -- Test that field values are not prepared
twice in get_db_prep_lookup().
"""
class NoopField(models.TextField):
def __init__(self, *args, **kwargs):
self.prep_value_count = 0
super(N... | [
"def",
"test_14786",
"(",
"self",
")",
":",
"class",
"NoopField",
"(",
"models",
".",
"TextField",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"prep_value_count",
"=",
"0",
"super",
"(",... | [
860,
4
] | [
878,
51
] | python | en | ['en', 'error', 'th'] | False |
TravisHookTests.test_travis_message | (self) |
Build notifications are generated by Travis after build completes.
The subject describes the repo and Stash "project". The
content describes the commits pushed.
|
Build notifications are generated by Travis after build completes. | def test_travis_message(self) -> None:
"""
Build notifications are generated by Travis after build completes.
The subject describes the repo and Stash "project". The
content describes the commits pushed.
"""
expected_message = (
"Author: josh_mandel\nBuild st... | [
"def",
"test_travis_message",
"(",
"self",
")",
"->",
"None",
":",
"expected_message",
"=",
"(",
"\"Author: josh_mandel\\nBuild status: Passed :thumbs_up:\\n\"",
"\"Details: [changes](https://github.com/hl7-fhir/fhir-sv\"",
"\"n/compare/6dccb98bcfd9...6c457d366a31), [build log](ht\"",
"\... | [
11,
4
] | [
30,
9
] | python | en | ['en', 'error', 'th'] | False |
MigrateTests.test_migrate | (self) |
Tests basic usage of the migrate command.
|
Tests basic usage of the migrate command.
| def test_migrate(self):
"""
Tests basic usage of the migrate command.
"""
# Make sure no tables are created
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
self.assertTableNotExists("migrations_book")
# Run th... | [
"def",
"test_migrate",
"(",
"self",
")",
":",
"# Make sure no tables are created",
"self",
".",
"assertTableNotExists",
"(",
"\"migrations_author\"",
")",
"self",
".",
"assertTableNotExists",
"(",
"\"migrations_tribble\"",
")",
"self",
".",
"assertTableNotExists",
"(",
... | [
30,
4
] | [
55,
52
] | python | en | ['en', 'error', 'th'] | False |
MigrateTests.test_migrate_list | (self) |
Tests --list output of migrate command
|
Tests --list output of migrate command
| def test_migrate_list(self):
"""
Tests --list output of migrate command
"""
stdout = six.StringIO()
call_command("migrate", list=True, stdout=stdout, verbosity=0)
self.assertIn("migrations", stdout.getvalue().lower())
self.assertIn("[ ] 0001_initial", stdout.getva... | [
"def",
"test_migrate_list",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"migrate\"",
",",
"list",
"=",
"True",
",",
"stdout",
"=",
"stdout",
",",
"verbosity",
"=",
"0",
")",
"self",
".",
"assertIn",
"(... | [
59,
4
] | [
78,
66
] | python | en | ['en', 'error', 'th'] | False |
MigrateTests.test_migrate_conflict_exit | (self) |
Makes sure that migrate exits if it detects a conflict.
|
Makes sure that migrate exits if it detects a conflict.
| def test_migrate_conflict_exit(self):
"""
Makes sure that migrate exits if it detects a conflict.
"""
with self.assertRaises(CommandError):
call_command("migrate", "migrations") | [
"def",
"test_migrate_conflict_exit",
"(",
"self",
")",
":",
"with",
"self",
".",
"assertRaises",
"(",
"CommandError",
")",
":",
"call_command",
"(",
"\"migrate\"",
",",
"\"migrations\"",
")"
] | [
82,
4
] | [
87,
49
] | python | en | ['en', 'error', 'th'] | False |
MigrateTests.test_sqlmigrate | (self) |
Makes sure that sqlmigrate does something.
|
Makes sure that sqlmigrate does something.
| def test_sqlmigrate(self):
"""
Makes sure that sqlmigrate does something.
"""
# Make sure the output is wrapped in a transaction
stdout = six.StringIO()
call_command("sqlmigrate", "migrations", "0001", stdout=stdout)
output = stdout.getvalue()
self.assertI... | [
"def",
"test_sqlmigrate",
"(",
"self",
")",
":",
"# Make sure the output is wrapped in a transaction",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"sqlmigrate\"",
",",
"\"migrations\"",
",",
"\"0001\"",
",",
"stdout",
"=",
"stdout",
")",
... | [
91,
4
] | [
116,
66
] | python | en | ['en', 'error', 'th'] | False |
MigrateTests.test_regression_22823_unmigrated_fk_to_migrated_model | (self) | ERROR: type should be string, got "\n https://code.djangoproject.com/ticket/22823\n\n Assuming you have 3 apps, `A`, `B`, and `C`, such that:\n\n * `A` has migrations\n * `B` has a migration we want to apply\n * `C` has no migrations, but has an FK to `A`\n\n When we try to migrate \"B\", an exception occurs because the\n \"B\" was not included in the ProjectState that is used to detect\n soft-applied migrations.\n " | ERROR: type should be string, got "\n https://code.djangoproject.com/ticket/22823" | def test_regression_22823_unmigrated_fk_to_migrated_model(self):
"""
https://code.djangoproject.com/ticket/22823
Assuming you have 3 apps, `A`, `B`, and `C`, such that:
* `A` has migrations
* `B` has a migration we want to apply
* `C` has no migrations, but has an FK to... | [
"def",
"test_regression_22823_unmigrated_fk_to_migrated_model",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"migrate\"",
",",
"\"migrated_unapplied_app\"",
",",
"stdout",
"=",
"stdout",
")"
] | [
124,
4
] | [
139,
72
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_conflict_exit | (self) |
Makes sure that makemigrations exits if it detects a conflict.
|
Makes sure that makemigrations exits if it detects a conflict.
| def test_makemigrations_conflict_exit(self):
"""
Makes sure that makemigrations exits if it detects a conflict.
"""
with self.assertRaises(CommandError):
call_command("makemigrations") | [
"def",
"test_makemigrations_conflict_exit",
"(",
"self",
")",
":",
"with",
"self",
".",
"assertRaises",
"(",
"CommandError",
")",
":",
"call_command",
"(",
"\"makemigrations\"",
")"
] | [
240,
4
] | [
245,
42
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_merge_no_conflict | (self) |
Makes sure that makemigrations exits if in merge mode with no conflicts.
|
Makes sure that makemigrations exits if in merge mode with no conflicts.
| def test_makemigrations_merge_no_conflict(self):
"""
Makes sure that makemigrations exits if in merge mode with no conflicts.
"""
stdout = six.StringIO()
try:
call_command("makemigrations", merge=True, stdout=stdout)
except CommandError:
self.fail(... | [
"def",
"test_makemigrations_merge_no_conflict",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"try",
":",
"call_command",
"(",
"\"makemigrations\"",
",",
"merge",
"=",
"True",
",",
"stdout",
"=",
"stdout",
")",
"except",
"CommandError... | [
249,
4
] | [
258,
75
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_no_app_sys_exit | (self) |
Makes sure that makemigrations exits if a non-existent app is specified.
|
Makes sure that makemigrations exits if a non-existent app is specified.
| def test_makemigrations_no_app_sys_exit(self):
"""
Makes sure that makemigrations exits if a non-existent app is specified.
"""
stderr = six.StringIO()
with self.assertRaises(SystemExit):
call_command("makemigrations", "this_app_does_not_exist", stderr=stderr)
... | [
"def",
"test_makemigrations_no_app_sys_exit",
"(",
"self",
")",
":",
"stderr",
"=",
"six",
".",
"StringIO",
"(",
")",
"with",
"self",
".",
"assertRaises",
"(",
"SystemExit",
")",
":",
"call_command",
"(",
"\"makemigrations\"",
",",
"\"this_app_does_not_exist\"",
"... | [
261,
4
] | [
268,
89
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_empty_no_app_specified | (self) |
Makes sure that makemigrations exits if no app is specified with 'empty' mode.
|
Makes sure that makemigrations exits if no app is specified with 'empty' mode.
| def test_makemigrations_empty_no_app_specified(self):
"""
Makes sure that makemigrations exits if no app is specified with 'empty' mode.
"""
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
self.assertRaises(CommandError, call_command, "makemigrat... | [
"def",
"test_makemigrations_empty_no_app_specified",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"MIGRATION_MODULES",
"=",
"{",
"\"migrations\"",
":",
"self",
".",
"migration_pkg",
"}",
")",
":",
"self",
".",
"assertRaises",
"(",
"CommandError",
",",
... | [
271,
4
] | [
276,
87
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.