Skip to content

Commit 82fe3f2

Browse files
🎨 lint tests and examples
1 parent 02c9549 commit 82fe3f2

File tree

9 files changed

+54
-51
lines changed

9 files changed

+54
-51
lines changed

examples/moving_files/with_application.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
async def example():
77
app = await client.app('application_id')
88
await app.move_file(
9-
origin='path/to/origin/file.py',
10-
dest='path/to/destination/file.py'
9+
origin='path/to/origin/file.py', dest='path/to/destination/file.py'
1110
)

examples/moving_files/with_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ async def example():
77
await client.move_app_file(
88
app_id='application_id',
99
origin='path/to/origin/file.py',
10-
dest='path/to/destination/file.py'
10+
dest='path/to/destination/file.py',
1111
)

tests/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ def create_zip(config: ConfigFile | str):
1919
config = config.content()
2020

2121
with zipfile.ZipFile(buffer, 'w') as zip_file:
22-
zip_file.writestr(
23-
'requirements.txt', 'discord.py'
24-
)
22+
zip_file.writestr('requirements.txt', 'discord.py')
2523

2624
zip_file.writestr('main.py', "print('ok')")
2725

28-
zip_file.writestr(
29-
'squarecloud.app', config
30-
)
26+
zip_file.writestr('squarecloud.app', config)
3127

3228
buffer.seek(0)
3329

@@ -40,5 +36,7 @@ async def wrapper(self, app: Application | Client, *args, **kwargs):
4036
if app.get_listener(endpoint):
4137
app.remove_listener(endpoint)
4238
return await func(self, app=app)
39+
4340
return wrapper
41+
4442
return decorator

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def app(client: Client) -> Application:
3232
display_name='normal_test',
3333
main='main.py',
3434
memory=512,
35-
subdomain='bhejbdhjwebjhde'
35+
subdomain='bhejbdhjwebjhde',
3636
)
3737
with Status('uploading test application...', spinner='point'):
3838
upload_data: UploadData = await client.upload_app(

tests/test_app.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
@pytest.mark.app
1212
class TestApp:
1313
async def test_magic_methods(self, app: Application):
14-
assert app.__repr__() == f'<{Application.__name__} tag={app.name} id={app.id}>'
14+
assert (
15+
app.__repr__()
16+
== f'<{Application.__name__} tag={app.name} id={app.id}>'
17+
)
1518

1619
async def test_app_data(self, app: Application):
1720
assert isinstance(await app.data(), squarecloud.AppData)
@@ -26,23 +29,23 @@ async def test_app_backup(self, app: Application):
2629
assert isinstance(await app.backup(), squarecloud.Backup)
2730

2831
async def test_app_github_integration(self, app: Application):
29-
assert isinstance(await app.github_integration(GITHUB_ACCESS_TOKEN), str)
32+
assert isinstance(
33+
await app.github_integration(GITHUB_ACCESS_TOKEN), str
34+
)
3035

3136
async def test_app_last_deploys(self, app: Application):
3237
assert isinstance(await app.last_deploys(), list)
3338

3439
@pytest.mark.skipif(
35-
lambda app: not app.is_website,
36-
reason='application is not website'
40+
lambda app: not app.is_website, reason='application is not website'
3741
)
3842
async def test_domain_analytics(self, app: Application):
3943
assert isinstance(
4044
await app.domain_analytics(), squarecloud.DomainAnalytics
4145
)
4246

4347
@pytest.mark.skipif(
44-
lambda app: not app.is_website,
45-
reason='application is not website'
48+
lambda app: not app.is_website, reason='application is not website'
4649
)
4750
async def test_set_custom_domain(self, app: Application):
4851
assert isinstance(await app.set_custom_domain('test.com.br'), str)

tests/test_capture_listeners.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ async def wrapper(self, app: Application):
1313
if app.get_listener(endpoint):
1414
app.remove_listener(endpoint)
1515
return await func(self, app=app)
16+
1617
return wrapper
18+
1719
return decorator
1820

1921

2022
@pytest.mark.asyncio(scope='class')
2123
@pytest.mark.listeners
2224
@pytest.mark.capture_listener
2325
class TestGeneralUse:
24-
2526
@_clear_listener_on_rerun(Endpoint.app_status())
2627
async def test_capture_status(self, app: Application):
2728
@app.capture(Endpoint.app_status(), force_raise=True)
2829
async def capture_status(before, after):
2930
assert before is None
3031
assert isinstance(after, StatusData)
32+
3133
await app.status()
3234

3335
@_clear_listener_on_rerun(Endpoint.backup())
@@ -45,15 +47,16 @@ async def test_capture_logs(self, app: Application):
4547
async def capture_logs(before, after):
4648
assert before is None
4749
assert isinstance(after, LogsData)
50+
4851
await app.logs()
4952

5053
@_clear_listener_on_rerun(Endpoint.app_data())
5154
async def test_app_data(self, app: Application):
52-
5355
@app.capture(Endpoint('APP_DATA'), force_raise=True)
5456
async def capture_data(before, after):
5557
assert before is None
5658
assert isinstance(after, AppData)
59+
5760
await app.data()
5861

5962
@_clear_listener_on_rerun(Endpoint.app_status())
@@ -79,7 +82,8 @@ async def capture_status(extra):
7982
async def test_manage_listeners(self, app: Application):
8083
listener: Listener
8184

82-
def callback_one(): pass
85+
def callback_one():
86+
pass
8387

8488
listener = app.include_listener(
8589
Listener(
@@ -90,14 +94,16 @@ def callback_one(): pass
9094
)
9195

9296
assert app.get_listener(Endpoint.app_status()).callback is callback_one
93-
assert app.get_listener(
94-
Endpoint.app_status()
95-
).endpoint == Endpoint.app_status()
97+
assert (
98+
app.get_listener(Endpoint.app_status()).endpoint
99+
== Endpoint.app_status()
100+
)
96101
assert not app.get_listener(Endpoint.app_status()).callback_params
97102
assert listener.callback is callback_one
98103
assert listener.endpoint == Endpoint.app_status()
99104

100-
def callback_two(): pass
105+
def callback_two():
106+
pass
101107

102108
with pytest.raises(errors.InvalidListener):
103109
app.include_listener(
@@ -112,12 +118,12 @@ def callback_two(): pass
112118
assert app.get_listener(Endpoint.app_status()) is None
113119

114120
listener = app.include_listener(
115-
Listener(
116-
app=app,
117-
endpoint=Endpoint.app_status(),
118-
callback=callback_two,
119-
)
121+
Listener(
122+
app=app,
123+
endpoint=Endpoint.app_status(),
124+
callback=callback_two,
120125
)
126+
)
121127
assert listener.callback is callback_two
122128
assert listener.endpoint == Endpoint.app_status()
123129

tests/test_files.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ async def test_files_type(self, app_files: list[FileInfo]):
2323

2424
assert file.type in ('file', 'directory')
2525

26-
async def test_read_file(self, client: Client, app: Application, app_files: list[FileInfo]):
26+
async def test_read_file(
27+
self, client: Client, app: Application, app_files: list[FileInfo]
28+
):
2729
file_read = await client.read_app_file(app.id, app_files[0].path)
2830
assert isinstance(file_read, BytesIO)
2931

@@ -40,7 +42,9 @@ async def test_delete_file(self, client: Client, app: Application):
4042
@pytest.mark.asyncio(scope='session')
4143
@pytest.mark.files
4244
class TestsApplication:
43-
async def test_files_list(self, app: Application, app_files: list[FileInfo]):
45+
async def test_files_list(
46+
self, app: Application, app_files: list[FileInfo]
47+
):
4448
TestsApplication.TEST_FILES = await app.files_list(path='/')
4549

4650
assert isinstance(app_files, list)
@@ -53,7 +57,9 @@ async def test_files_list(self, app: Application, app_files: list[FileInfo]):
5357

5458
assert file.type in ('file', 'directory')
5559

56-
async def test_read_file(self, app: Application, app_files: list[FileInfo]):
60+
async def test_read_file(
61+
self, app: Application, app_files: list[FileInfo]
62+
):
5763
file_read = await app.read_file(app_files[0].path)
5864
assert isinstance(file_read, BytesIO)
5965

tests/test_request_listeners.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525

2626
def _clear_listener_on_rerun(endpoint: Endpoint):
2727
def decorator(func):
28-
async def wrapper(self, client: Client, app: Application):
28+
async def wrapper(self, client: Client, app: Application):
2929
if client.get_listener(endpoint):
3030
client.remove_listener(endpoint)
3131
return await func(self, client, app)
32+
3233
return wrapper
34+
3335
return decorator
3436

3537

@@ -144,9 +146,7 @@ async def test_listener(response: Response):
144146

145147
@_clear_listener_on_rerun(Endpoint.files_list())
146148
async def test_request_app_files_list(
147-
self,
148-
client: Client,
149-
app: Application
149+
self, client: Client, app: Application
150150
):
151151
endpoint: Endpoint = Endpoint.files_list()
152152
expected_result: list[FileInfo] | None
@@ -205,9 +205,7 @@ async def test_listener(response: Response):
205205
nonlocal expected_response
206206
expected_response = response
207207

208-
expected_result = await client.delete_app_file(
209-
app.id, '/test.txt'
210-
)
208+
expected_result = await client.delete_app_file(app.id, '/test.txt')
211209
assert isinstance(expected_result, Response)
212210
assert isinstance(expected_response, Response)
213211

@@ -222,9 +220,7 @@ async def test_listener(response: Response):
222220
nonlocal expected_response
223221
expected_response = response
224222

225-
expected_result = await client.commit(
226-
app.id, File('tests/test.txt')
227-
)
223+
expected_result = await client.commit(app.id, File('tests/test.txt'))
228224
assert isinstance(expected_result, Response)
229225
assert isinstance(expected_response, Response)
230226

@@ -277,8 +273,7 @@ async def test_listener(response: Response):
277273
assert isinstance(expected_response, Response)
278274

279275
@pytest.mark.skipif(
280-
lambda app: not app.is_website,
281-
reason='application is not website'
276+
lambda app: not app.is_website, reason='application is not website'
282277
)
283278
@_clear_listener_on_rerun(Endpoint.domain_analytics())
284279
async def test_domain_analytics(self, client: Client, app: Application):
@@ -296,8 +291,7 @@ async def test_listener(response: Response):
296291
assert isinstance(expected_response, Response)
297292

298293
@pytest.mark.skipif(
299-
lambda app: not app.is_website,
300-
reason='application is not website'
294+
lambda app: not app.is_website, reason='application is not website'
301295
)
302296
@_clear_listener_on_rerun(Endpoint.custom_domain())
303297
async def test_set_custom_domain(self, client: Client, app: Application):
@@ -367,7 +361,7 @@ async def test_listener(response: Response):
367361
assert isinstance(expected_response, Response)
368362

369363
@_clear_listener_on_rerun(Endpoint.dns_records())
370-
async def test_move_app_file(self, client: Client, app: Application):
364+
async def test_dns_records(self, client: Client, app: Application):
371365
endpoint: Endpoint = Endpoint.dns_records()
372366
expected_result: list[DNSRecord] | None
373367
expected_response: Response | None = None

tests/test_upload_app.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ async def test_bad_memory_upload(self, client: Client):
8888
config = ConfigFile(
8989
display_name='memory_test',
9090
main='main.py',
91-
memory=
92-
256,
91+
memory=256,
9392
).content()
9493
with pytest.raises(errors.BadMemory):
9594
config = config.replace('256', '1')
@@ -100,9 +99,7 @@ async def test_bad_memory_upload(self, client: Client):
10099

101100
async def test_missing_memory_upload(self, client: Client):
102101
config = ConfigFile(
103-
display_name='memory_test',
104-
main='main.py',
105-
memory=256
102+
display_name='memory_test', main='main.py', memory=256
106103
).content()
107104
config = config.replace('256', '')
108105
with pytest.raises(errors.MissingMemory):

0 commit comments

Comments
 (0)