function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def __init__(
self,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
value: Optional[List["JobResponse"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
properties: Optional["RouteProperties"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
lock_duration_as_iso8601: Optional[datetime.timedelta] = None,
ttl_as_iso8601: Optional[datetime.timedelta] = None,
max_delivery_count: Optional[int] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
value: Optional[str] = None,
localized_value: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
display: Optional["OperationDisplay"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
name: str,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
message: Optional[str] = None,
severity: Optional[Union[str, "RouteErrorSeverity"]] = None,
location: Optional["RouteErrorRange"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
line: Optional[int] = None,
column: Optional[int] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
start: Optional["RouteErrorPosition"] = None,
end: Optional["RouteErrorPosition"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
name: str,
source: Union[str, "RoutingSource"],
endpoint_names: List[str],
is_enabled: bool,
condition: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
service_bus_queues: Optional[List["RoutingServiceBusQueueEndpointProperties"]] = None,
service_bus_topics: Optional[List["RoutingServiceBusTopicEndpointProperties"]] = None,
event_hubs: Optional[List["RoutingEventHubProperties"]] = None,
storage_containers: Optional[List["RoutingStorageContainerProperties"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
connection_string: str,
name: str,
subscription_id: Optional[str] = None,
resource_group: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
body: Optional[str] = None,
app_properties: Optional[Dict[str, str]] = None,
system_properties: Optional[Dict[str, str]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
endpoints: Optional["RoutingEndpoints"] = None,
routes: Optional[List["RouteProperties"]] = None,
fallback_route: Optional["FallbackRouteProperties"] = None,
enrichments: Optional[List["EnrichmentProperties"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
connection_string: str,
name: str,
subscription_id: Optional[str] = None,
resource_group: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
connection_string: str,
name: str,
subscription_id: Optional[str] = None,
resource_group: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
connection_string: str,
name: str,
container_name: str,
subscription_id: Optional[str] = None,
resource_group: Optional[str] = None,
file_name_format: Optional[str] = None,
batch_frequency_in_seconds: Optional[int] = None,
max_chunk_size_in_bytes: Optional[int] = None,
encoding: Optional[Union[str, "RoutingStorageContainerPropertiesEncoding"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
tags: Optional[Any] = None,
properties: Optional["RoutingTwinProperties"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
desired: Optional[Any] = None,
reported: Optional[Any] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
key_name: str,
rights: Union[str, "AccessRights"],
primary_key: Optional[str] = None,
secondary_key: Optional[str] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
value: Optional[List["SharedAccessSignatureAuthorizationRule"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
connection_string: str,
container_name: str,
sas_ttl_as_iso8601: Optional[datetime.timedelta] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
tags: Optional[Dict[str, str]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
routing_source: Optional[Union[str, "RoutingSource"]] = None,
message: Optional["RoutingMessage"] = None,
twin: Optional["RoutingTwin"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
routes: Optional[List["MatchedRoute"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
route: "RouteProperties",
message: Optional["RoutingMessage"] = None,
twin: Optional["RoutingTwin"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
result: Optional[Union[str, "TestResultStatus"]] = None,
details: Optional["TestRouteResultDetails"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
compilation_errors: Optional[List["RouteCompilationError"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
id: Optional[str] = None,
type: Optional[str] = None,
unit: Optional[str] = None,
current_value: Optional[int] = None,
limit: Optional[int] = None,
name: Optional["Name"] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(
self,
*,
value: Optional[List["UserSubscriptionQuota"]] = None,
**kwargs | Azure/azure-sdk-for-python | [
3526,
2256,
3526,
986,
1335285972
] |
def __init__(self, msg, code):
super(CustomException, self).__init__(msg)
self.code = code | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_call_api_call(self):
settings = _CallSettings()
my_callable = api_callable.create_api_call(
lambda _req, _timeout: 42, settings)
self.assertEqual(my_callable(None), 42) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_call_kwargs(self):
settings = _CallSettings(kwargs={'key': 'value'})
my_callable = api_callable.create_api_call(
lambda _req, _timeout, **kwargs: kwargs['key'], settings)
self.assertEqual(my_callable(None), 'value')
self.assertEqual(my_callable(None, CallOptions(key='updated')),
'updated') | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_retry(self, mock_exc_to_code, mock_time):
mock_exc_to_code.side_effect = lambda e: e.code
to_attempt = 3
retry = RetryOptions(
[_FAKE_STATUS_CODE_1],
BackoffSettings(0, 0, 0, 0, 0, 0, 1))
# Succeeds on the to_attempt'th call, and never again afterward
mock_call = mock.Mock()
mock_call.side_effect = ([CustomException('', _FAKE_STATUS_CODE_1)] *
(to_attempt - 1) + [mock.DEFAULT])
mock_call.return_value = 1729
mock_time.return_value = 0
settings = _CallSettings(timeout=0, retry=retry)
my_callable = api_callable.create_api_call(mock_call, settings)
self.assertEqual(my_callable(None), 1729)
self.assertEqual(mock_call.call_count, to_attempt) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def __init__(self, page_token=0):
self.page_token = page_token | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def __init__(self, nums=(), next_page_token=0):
self.nums = nums
self.next_page_token = next_page_token | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def grpc_return_value(request, *dummy_args, **dummy_kwargs):
start = int(request.page_token)
if start > 0 and start < page_size * pages_to_stream:
return PageStreamingResponse(
nums=list(range(start,
start + page_size)),
next_page_token=start + page_size)
elif start >= page_size * pages_to_stream:
return PageStreamingResponse()
else:
return PageStreamingResponse(nums=list(range(page_size)),
next_page_token=page_size) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_bundling_page_streaming_error(self):
settings = _CallSettings(
page_descriptor=object(), bundle_descriptor=object(),
bundler=object())
with self.assertRaises(ValueError):
api_callable.create_api_call(lambda _req, _timeout: 42, settings) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def __init__(self, elements=None):
self.elements = elements | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def my_func(request, dummy_timeout):
return len(request.elements) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_construct_settings(self):
defaults = api_callable.construct_settings(
_SERVICE_NAME, _A_CONFIG, dict(), _RETRY_DICT,
bundle_descriptors=_BUNDLE_DESCRIPTORS,
page_descriptors=_PAGE_DESCRIPTORS,
kwargs={'key1': 'value1'})
settings = defaults['bundling_method']
self.assertAlmostEqual(settings.timeout, 25.0)
self.assertIsInstance(settings.bundler, bundling.Executor)
self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)
self.assertIsNone(settings.page_descriptor)
self.assertIsInstance(settings.retry, RetryOptions)
self.assertEqual(settings.kwargs, {'key1': 'value1'})
settings = defaults['page_streaming_method']
self.assertAlmostEqual(settings.timeout, 12.0)
self.assertIsNone(settings.bundler)
self.assertIsNone(settings.bundle_descriptor)
self.assertIsInstance(settings.page_descriptor, PageDescriptor)
self.assertIsInstance(settings.retry, RetryOptions)
self.assertEqual(settings.kwargs, {'key1': 'value1'}) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_construct_settings_override2(self):
_override = {
'interfaces': {
_SERVICE_NAME: {
'retry_codes': {
'bar_retry': [],
'baz_retry': ['code_a']
},
'retry_params': {
'default': {
'initial_retry_delay_millis': 1000,
'retry_delay_multiplier': 1.2,
'max_retry_delay_millis': 10000,
'initial_rpc_timeout_millis': 3000,
'rpc_timeout_multiplier': 1.3,
'max_rpc_timeout_millis': 30000,
'total_timeout_millis': 300000
},
},
'methods': {
'BundlingMethod': {
'retry_params_name': 'default',
'retry_codes_name': 'baz_retry',
},
},
}
}
}
defaults = api_callable.construct_settings(
_SERVICE_NAME, _A_CONFIG, _override, _RETRY_DICT,
bundle_descriptors=_BUNDLE_DESCRIPTORS,
page_descriptors=_PAGE_DESCRIPTORS)
settings = defaults['bundling_method']
backoff = settings.retry.backoff_settings
self.assertEqual(backoff.initial_retry_delay_millis, 1000)
self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_a']])
self.assertIsInstance(settings.bundler, bundling.Executor)
self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)
# page_streaming_method is unaffected because it's not specified in
# overrides. 'bar_retry' or 'default' definitions in overrides should
# not affect the methods which are not in the overrides.
settings = defaults['page_streaming_method']
backoff = settings.retry.backoff_settings
self.assertEqual(backoff.initial_retry_delay_millis, 100)
self.assertEqual(backoff.retry_delay_multiplier, 1.2)
self.assertEqual(backoff.max_retry_delay_millis, 1000)
self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_c']]) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def test_catch_error(self):
def abortion_error_func(*dummy_args, **dummy_kwargs):
raise CustomException(None, None)
def other_error_func(*dummy_args, **dummy_kwargs):
raise AnotherException
gax_error_callable = api_callable.create_api_call(
abortion_error_func, _CallSettings())
self.assertRaises(GaxError, gax_error_callable, None)
other_error_callable = api_callable.create_api_call(
other_error_func, _CallSettings())
self.assertRaises(AnotherException, other_error_callable, None) | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def value_error_func(*dummy_args, **dummy_kwargs):
raise invalid_attribute_exc | ininex/geofire-python | [
6,
5,
6,
3,
1486450134
] |
def creating_document_object_with_string_should_automatically_parse(self):
html = '<html></html>'
with patch('structominer.Document.parse') as mocked_parse:
doc = Document(html)
mocked_parse.assert_called_with(html) | aGHz/structominer | [
17,
3,
17,
7,
1393007493
] |
def document_should_store_fields_in_order(self):
class Doc(Document):
three = Mock(Field, _field_counter=3)
two = Mock(Field, _field_counter=2)
one = Mock(Field, _field_counter=1)
doc = Doc()
self.assertEquals([field._field_counter for field in doc._fields.values()], [1, 2, 3]) | aGHz/structominer | [
17,
3,
17,
7,
1393007493
] |
def initialize(cls):
"""
Initialize pypm if not already initialized.
"""
if cls.initialized:
return
pypm.Initialize()
cls._gatherDeviceInfo()
cls.initialized = True | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def _gatherDeviceInfo(cls):
for devno in range(pypm.CountDevices()):
info = pypm.GetDeviceInfo(devno)
insouts = {'output': None, 'input': None}
m = cls.deviceMap.setdefault(info[1], insouts)
if info[3]:
cls.outputs.append(devno)
m['output'] = devno
if info[2]:
cls.inputs.append(devno)
m['input'] = devno
cls.inputNames = dict(
(v['input'], k) for (k, v) in cls.deviceMap.items()
if v['input'] is not None
)
cls.outputNames = dict(
(v['output'], k) for (k, v) in cls.deviceMap.items()
if v['output'] is not None
) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def getInput(cls, dev):
"""
Get an input with devive number 'dev' - dev may also be string matching
the target device. If the input was previously loaded this will return
the cached device.
"""
no = dev
if isinstance(dev, basestring):
no = cls.deviceMap[dev]['input']
key = ('input', no)
if key not in cls._channels:
cls._channels[key] = pypm.Input(no)
return cls._channels[key] | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def getOutput(cls, dev):
"""
Get output with devive number 'dev' - dev may also be string matching
the target device. If the output was previously loaded this will return
the cached device.
"""
no = dev
if isinstance(dev, basestring):
no = cls.deviceMap[dev]['output']
key = ('output', no)
if key not in cls._channels:
cls._channels[key] = pypm.Output(no)
return cls._channels[key] | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def printDeviceSummary(cls, printer=None):
"""
Print device summary - inputs followed by outputs.
"""
if printer is None:
def printer(line):
print line
printer('Inputs:')
for devno in cls.inputs:
printer('... %d %r' % (devno, cls.inputNames[devno]))
printer('Outputs:')
for devno in cls.outputs:
printer('... %d %r' % (devno, cls.outputNames[devno])) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def _add_global(name, arity, v):
globals()[name] = v
FUNCTIONS[v] = name
FUNCTION_ARITY[v] = arity
__all__.append(name) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def debug_event(event):
print event | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __init__(self, midiInput, handlers, clock=None):
self.clock = getClock(clock)
self.midiInput = midiInput
self.handlers = handlers | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __call__(self):
"""
Call all our handlers with buffered events (max of 32 per call
are processed).
"""
for message in self.midiInput.Read(32):
for call in self.handlers:
call(message) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __call__(self, message):
"""
Parse method and call method on self based on midi function. For
example, if function is NOTEON_CHAN1, this will call our method
noteon(), etc. If a message has a channel as part of it's function,
this will be the first argument. After the first optional channel
argument, remaining positional arguments are passed to the method in
the same order as specified in MIDI. Not all MIDI functions need to be
supplied or implemented in subclass.
"""
packet, timestamp = message
func, arg1, arg2, _pad = packet
args = [arg1, arg2][:FUNCTION_ARITY.get(func, 0)]
args.append(timestamp)
funcname = FUNCTIONS[func]
tokens = funcname.split('_')
if len(tokens) == 2:
type, channel = tokens
channel = int(channel[4:])
method = getattr(self, type.lower(), None)
if method is None:
debug('No handler defined for midi event of type: %s' % type)
method(channel, *args) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def noteoff(self, channel, note, velocity, timestamp):
pass | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def playnote(cls, note, velocity):
pass | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def stopnote(cls, note):
pass | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __init__(self, instrs):
self.instrs = instrs | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def noteoff(self, channel, note, velocity, timestamp):
"""
Immediately stop instrument at channel with given note. The velocity
and timestamp arguments are ignored. This is a noop if no instrument
is mapped to the given channel.
"""
self.instrs.get(channel, _DummyInstrument).stopnote(note) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __init__(self, callback, sustain=False):
"""
callback: handler to receive chords
sustain: if True, only call our callback with noteon events
"""
self.callback = callback
self.sustain = sustain
self._chord = [] | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def noteoff(self, channel, note, velocity, timestamp):
"""
Remove note from chord.
If the attribute `sustain` is `True` then we do not
call callback with the updated chord.
Note that channel, velocity and timestamp arguments are ignored.
"""
debug('noteoff channel=%s note=%s velocity=%s t=%s' % (
channel, note, velocity, timestamp))
if note in self._chord:
self._chord.remove(note)
if not self.sustain:
debug('calling %s' % self.callback)
self.callback(list(self._chord)) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __init__(self, noteonCallback, noteoffCallback):
self.noteonCallback = noteonCallback
self.noteoffCallback = noteoffCallback | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def noteoff(self, channel, note, velocity, timestamp):
"""
Call noteoffCallback with the note.
"""
self.noteoffCallback(note) | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def __init__(self, midiOut, clock=None):
self.clock = getClock(clock)
self.midiOut = midiOut
self._started = False | djfroofy/beatlounge | [
9,
3,
9,
11,
1330403825
] |
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
with contextlib.closing(socket.socket(family, type, proto)) as l:
l.bind(("localhost", 0))
l.listen(5)
c = socket.socket(family, type, proto)
try:
c.connect(l.getsockname())
caddr = c.getsockname()
while True:
a, addr = l.accept()
# check that we've got the correct client
if addr == caddr:
return c, a
a.close()
except OSError:
c.close()
raise | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def make_socketpair(self):
rd, wr = socketpair()
self.addCleanup(rd.close)
self.addCleanup(wr.close)
return rd, wr | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_unregister(self):
s, rd, wr = self.test_register()
s.unregister(rd)
s.unregister(wr)
self.assertNotIn(rd, s.socket_map)
self.assertNotIn(wr, s.socket_map) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_modify(self):
s, rd, wr = self.test_register()
s.modify(rd, s.WRITE)
s.modify(wr, s.READ) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_close(self):
s, rd, wr = self.test_register()
s.close()
self.assertEqual(s.socket_map, {}) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def close(self):
1 / 0 | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_close_w_handler_ebadf_exc(self):
# Simulate an exception when close()ing a socket handler.
# Exception should be ignored (and not logged).
class Handler(AsyncChat):
def close(self):
raise OSError(errno.EBADF, "")
s = self.ioloop_class()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
handler = Handler(rd)
s.register(rd, handler, s.READ)
with mock.patch("pyftpdlib.ioloop.logger.error") as m:
s.close()
assert not m.called | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_select_eintr(self):
# EINTR is supposed to be ignored
with mock.patch('pyftpdlib.ioloop.select.select',
side_effect=select.error()) as m:
m.side_effect.errno = errno.EINTR
s, rd, wr = self.test_register()
s.poll(0)
# ...but just that
with mock.patch('pyftpdlib.ioloop.select.select',
side_effect=select.error()) as m:
m.side_effect.errno = errno.EBADF
s, rd, wr = self.test_register()
self.assertRaises(select.error, s.poll, 0) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_eintr_on_poll(self):
# EINTR is supposed to be ignored
with mock.patch(self.poller_mock, return_vaue=mock.Mock()) as m:
if not PY3:
m.return_value.poll.side_effect = select.error
m.return_value.poll.side_effect.errno = errno.EINTR
else:
m.return_value.poll.side_effect = OSError(errno.EINTR, "")
s, rd, wr = self.test_register()
s.poll(0)
assert m.called
# ...but just that
with mock.patch(self.poller_mock, return_vaue=mock.Mock()) as m:
if not PY3:
m.return_value.poll.side_effect = select.error
m.return_value.poll.side_effect.errno = errno.EBADF
else:
m.return_value.poll.side_effect = OSError(errno.EBADF, "")
s, rd, wr = self.test_register()
self.assertRaises(select.error, s.poll, 0)
assert m.called | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_enoent_ebadf_on_unregister(self):
# ENOENT and EBADF are supposed to be ignored
for errnum in (errno.EBADF, errno.ENOENT):
with mock.patch(self.poller_mock, return_vaue=mock.Mock()) as m:
m.return_value.unregister.side_effect = \
EnvironmentError(errnum, "")
s, rd, wr = self.test_register()
s.unregister(rd)
# ...but just those
with mock.patch(self.poller_mock, return_vaue=mock.Mock()) as m:
m.return_value.unregister.side_effect = \
EnvironmentError(errno.EEXIST, "")
s, rd, wr = self.test_register()
self.assertRaises(EnvironmentError, s.unregister, rd) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def setUp(self):
self.ioloop = IOLoop.instance()
for task in self.ioloop.sched._tasks:
if not task.cancelled:
task.cancel()
del self.ioloop.sched._tasks[:] | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_interface(self):
def fun():
return 0
self.assertRaises(AssertionError, self.ioloop.call_later, -1, fun)
x = self.ioloop.call_later(3, fun)
self.assertEqual(x.cancelled, False)
x.cancel()
self.assertEqual(x.cancelled, True)
self.assertRaises(AssertionError, x.call)
self.assertRaises(AssertionError, x.reset)
x.cancel() | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def fun(x):
l.append(x) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_reset(self):
def fun(x):
l.append(x)
l = []
self.ioloop.call_later(0.01, fun, 0.01)
self.ioloop.call_later(0.02, fun, 0.02)
self.ioloop.call_later(0.03, fun, 0.03)
x = self.ioloop.call_later(0.04, fun, 0.04)
self.ioloop.call_later(0.05, fun, 0.05)
time.sleep(0.1)
x.reset()
self.scheduler()
self.assertEqual(l, [0.01, 0.02, 0.03, 0.05, 0.04]) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def fun(x):
l.append(x) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_errback(self):
l = []
self.ioloop.call_later(
0.0, lambda: 1 // 0, _errback=lambda: l.append(True))
self.scheduler()
self.assertEqual(l, [True]) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test__lt__(self):
a = self.ioloop.call_later(0.01, lambda: 0, 0.01)
b = self.ioloop.call_later(0.02, lambda: 0, 0.02)
self.assertTrue(a < b) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def setUp(self):
self.ioloop = IOLoop.instance()
for task in self.ioloop.sched._tasks:
if not task.cancelled:
task.cancel()
del self.ioloop.sched._tasks[:] | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_interface(self):
def fun():
return 0
self.assertRaises(AssertionError, self.ioloop.call_every, -1, fun)
x = self.ioloop.call_every(3, fun)
self.assertEqual(x.cancelled, False)
x.cancel()
self.assertEqual(x.cancelled, True)
self.assertRaises(AssertionError, x.call)
self.assertRaises(AssertionError, x.reset)
x.cancel() | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def fun():
l1.append(None) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_multi_0_timeout(self):
# make sure a 0 timeout callback is called as many times
# as the number of loops
def fun():
l.append(None)
l = []
self.ioloop.call_every(0, fun)
for x in range(100):
self.ioloop.sched.poll()
self.assertEqual(len(l), 100) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_low_and_high_timeouts(self):
# make sure a callback with a lower timeout is called more
# frequently than another with a greater timeout
def fun():
l1.append(None)
l1 = []
self.ioloop.call_every(0.001, fun)
self.scheduler()
def fun():
l2.append(None)
l2 = []
self.ioloop.call_every(0.005, fun)
self.scheduler(timeout=0.01)
self.assertTrue(len(l1) > len(l2)) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def fun():
l.append(None) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_errback(self):
l = []
self.ioloop.call_every(
0.0, lambda: 1 // 0, _errback=lambda: l.append(True))
self.scheduler()
self.assertTrue(l) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def get_connected_handler(self):
s = socket.socket()
self.addCleanup(s.close)
ac = AsyncChat(sock=s)
self.addCleanup(ac.close)
return ac | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_send_disconnect(self):
ac = self.get_connected_handler()
for errnum in pyftpdlib.ioloop._ERRNOS_DISCONNECTED:
with mock.patch("pyftpdlib.ioloop.socket.socket.send",
side_effect=socket.error(errnum, "")) as send:
with mock.patch.object(ac, "handle_close") as handle_close:
self.assertEqual(ac.send(b"x"), 0)
assert send.called
assert handle_close.called | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_recv_disconnect(self):
ac = self.get_connected_handler()
for errnum in pyftpdlib.ioloop._ERRNOS_DISCONNECTED:
with mock.patch("pyftpdlib.ioloop.socket.socket.recv",
side_effect=socket.error(errnum, "")) as send:
with mock.patch.object(ac, "handle_close") as handle_close:
self.assertEqual(ac.recv(b"x"), b'')
assert send.called
assert handle_close.called | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_bind_af_unspecified_err(self):
ac = Acceptor()
with mock.patch.object(
ac, "bind",
side_effect=socket.error(errno.EBADF, "")) as m:
self.assertRaises(socket.error,
ac.bind_af_unspecified, ("localhost", 0))
assert m.called
self.assertIsNone(ac.socket) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def test_handle_accept_typeerror(self):
# https://github.com/giampaolo/pyftpdlib/issues/91
ac = Acceptor()
with mock.patch.object(ac, "accept", side_effect=TypeError) as m:
ac.handle_accept()
assert m.called
self.assertIsNone(ac.socket) | aliyun/oss-ftp | [
61,
20,
61,
15,
1450580546
] |
def lru_cache(maxsize=None): # pylint: disable=unused-argument
"""
Identity implementation of ``lru_cache`` for fallback.
"""
return lambda func: func | Phyks/Flatisfy | [
16,
6,
16,
4,
1492106528
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.