Skip to content

Commit 944b752

Browse files
committed
Apply code review feedback
1 parent e406365 commit 944b752

File tree

2 files changed

+76
-73
lines changed

2 files changed

+76
-73
lines changed

b2sdk/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(
8484
services=self, max_workers=max_upload_workers
8585
)
8686
self.copy_manager = self.COPY_MANAGER_CLASS(services=self, max_workers=max_copy_workers)
87+
assert max_download_streams_per_file is None or max_download_streams_per_file >= 1
8788
self.download_manager = self.DOWNLOAD_MANAGER_CLASS(
8889
services=self,
8990
max_workers=max_download_workers,

test/unit/v_all/test_api.py

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -22,82 +22,84 @@
2222
from ..test_base import TestBase
2323

2424

25-
class TestServices(TestBase):
26-
def setUp(self):
25+
class DummyA:
26+
def __init__(self, *args, **kwargs):
27+
pass
28+
29+
30+
class DummyB:
31+
def __init__(self, *args, **kwargs):
32+
pass
33+
34+
35+
class TestServices:
36+
@pytest.mark.apiver(from_ver=2)
37+
@pytest.mark.parametrize(
38+
('kwargs', '_raw_api_class'),
39+
[
40+
[
41+
{
42+
'max_upload_workers': 1,
43+
'max_copy_workers': 2,
44+
'max_download_workers': 3,
45+
'save_to_buffer_size': 4,
46+
'check_download_hash': False,
47+
'max_download_streams_per_file': 5,
48+
},
49+
DummyA,
50+
],
51+
[
52+
{
53+
'max_upload_workers': 2,
54+
'max_copy_workers': 3,
55+
'max_download_workers': 4,
56+
'save_to_buffer_size': 5,
57+
'check_download_hash': True,
58+
'max_download_streams_per_file': 6,
59+
},
60+
DummyB,
61+
],
62+
],
63+
) # yapf: disable
64+
def test_api_initialization(self, kwargs, _raw_api_class):
2765
self.account_info = InMemoryAccountInfo()
2866
self.cache = InMemoryCache()
2967

30-
@pytest.mark.apiver(from_ver=2)
31-
def test_api_initialization(self):
32-
class DummyA:
33-
def __init__(self, *args, **kwargs):
34-
pass
35-
36-
class DummyB:
37-
def __init__(self, *args, **kwargs):
38-
pass
39-
40-
for kwargs, _raw_api_class in [
41-
(
42-
dict(
43-
max_upload_workers = 1,
44-
max_copy_workers = 2,
45-
max_download_workers = 3,
46-
save_to_buffer_size = 4,
47-
check_download_hash = False,
48-
max_download_streams_per_file = 5,
49-
),
50-
DummyA,
51-
),
52-
(
53-
dict(
54-
max_upload_workers = 2,
55-
max_copy_workers = 3,
56-
max_download_workers = 4,
57-
save_to_buffer_size = 5,
58-
check_download_hash = True,
59-
max_download_streams_per_file = 6,
60-
),
61-
DummyB,
62-
)
63-
]: # yapf: disable
64-
65-
api_config = B2HttpApiConfig(_raw_api_class=_raw_api_class)
66-
67-
self.api = B2Api(
68-
self.account_info,
69-
self.cache,
70-
api_config=api_config,
71-
72-
**kwargs
73-
) # yapf: disable
74-
75-
assert self.api.account_info is self.account_info
76-
assert self.api.api_config is api_config
77-
assert self.api.cache is self.cache
78-
79-
assert self.api.session.account_info is self.account_info
80-
assert self.api.session.cache is self.cache
81-
assert isinstance(self.api.session.raw_api, _raw_api_class)
82-
83-
assert isinstance(self.api.file_version_factory, B2Api.FILE_VERSION_FACTORY_CLASS)
84-
assert isinstance(
85-
self.api.download_version_factory,
86-
B2Api.DOWNLOAD_VERSION_FACTORY_CLASS,
87-
)
88-
89-
services = self.api.services
90-
assert isinstance(services, B2Api.SERVICES_CLASS)
91-
92-
# max copy/upload/download workers could only be verified with mocking
93-
94-
download_manager = services.download_manager
95-
assert isinstance(download_manager, services.DOWNLOAD_MANAGER_CLASS)
96-
97-
assert download_manager.write_buffer_size == kwargs['save_to_buffer_size']
98-
assert download_manager.check_hash == kwargs['check_download_hash']
99-
assert download_manager.strategies[0].max_streams == kwargs[
100-
'max_download_streams_per_file']
68+
api_config = B2HttpApiConfig(_raw_api_class=_raw_api_class)
69+
70+
self.api = B2Api(
71+
self.account_info,
72+
self.cache,
73+
api_config=api_config,
74+
75+
**kwargs
76+
) # yapf: disable
77+
78+
assert self.api.account_info is self.account_info
79+
assert self.api.api_config is api_config
80+
assert self.api.cache is self.cache
81+
82+
assert self.api.session.account_info is self.account_info
83+
assert self.api.session.cache is self.cache
84+
assert isinstance(self.api.session.raw_api, _raw_api_class)
85+
86+
assert isinstance(self.api.file_version_factory, B2Api.FILE_VERSION_FACTORY_CLASS)
87+
assert isinstance(
88+
self.api.download_version_factory,
89+
B2Api.DOWNLOAD_VERSION_FACTORY_CLASS,
90+
)
91+
92+
services = self.api.services
93+
assert isinstance(services, B2Api.SERVICES_CLASS)
94+
95+
# max copy/upload/download workers could only be verified with mocking
96+
97+
download_manager = services.download_manager
98+
assert isinstance(download_manager, services.DOWNLOAD_MANAGER_CLASS)
99+
100+
assert download_manager.write_buffer_size == kwargs['save_to_buffer_size']
101+
assert download_manager.check_hash == kwargs['check_download_hash']
102+
assert download_manager.strategies[0].max_streams == kwargs['max_download_streams_per_file']
101103

102104

103105
class TestApi(TestBase):

0 commit comments

Comments
 (0)