Skip to content

Commit 076f94b

Browse files
committed
Format code with Black
1 parent 7aad94e commit 076f94b

45 files changed

Lines changed: 1638 additions & 1299 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Tests/conftest.py

Lines changed: 55 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def app():
1515
"""Create a basic jsweb application for testing."""
1616
from jsweb import App
17-
17+
1818
app = App(__name__)
1919
app.config.TESTING = True
2020
return app
@@ -30,13 +30,14 @@ def client(app):
3030
@pytest.fixture
3131
def config():
3232
"""Provide a test configuration."""
33+
3334
class TestConfig:
3435
DEBUG = True
3536
TESTING = True
3637
SECRET_KEY = "test-secret-key"
3738
DATABASE_URL = "sqlite:///:memory:"
3839
SQLALCHEMY_ECHO = False
39-
40+
4041
return TestConfig()
4142

4243

@@ -53,92 +54,88 @@ def sample_form_data():
5354
@pytest.fixture
5455
def sample_json_data():
5556
"""Provide sample JSON data for testing."""
56-
return {
57-
"name": "Test User",
58-
"email": "test@example.com",
59-
"age": 30,
60-
"active": True
61-
}
57+
return {"name": "Test User", "email": "test@example.com", "age": 30, "active": True}
6258

6359

6460
@pytest.fixture
6561
def fake_environ():
6662
"""Provide a fake WSGI environ dict for request testing."""
63+
6764
def _make_environ(
68-
method='GET',
69-
path='/',
70-
query_string='',
71-
content_type='application/x-www-form-urlencoded',
65+
method="GET",
66+
path="/",
67+
query_string="",
68+
content_type="application/x-www-form-urlencoded",
7269
content_length=0,
73-
body=b'',
74-
cookies=''
70+
body=b"",
71+
cookies="",
7572
):
7673
return {
77-
'REQUEST_METHOD': method,
78-
'CONTENT_TYPE': content_type,
79-
'CONTENT_LENGTH': str(content_length),
80-
'PATH_INFO': path,
81-
'QUERY_STRING': query_string,
82-
'HTTP_COOKIE': cookies,
83-
'wsgi.input': BytesIO(body),
84-
'SERVER_NAME': 'testserver',
85-
'SERVER_PORT': '80',
86-
'wsgi.url_scheme': 'http',
74+
"REQUEST_METHOD": method,
75+
"CONTENT_TYPE": content_type,
76+
"CONTENT_LENGTH": str(content_length),
77+
"PATH_INFO": path,
78+
"QUERY_STRING": query_string,
79+
"HTTP_COOKIE": cookies,
80+
"wsgi.input": BytesIO(body),
81+
"SERVER_NAME": "testserver",
82+
"SERVER_PORT": "80",
83+
"wsgi.url_scheme": "http",
8784
}
88-
85+
8986
return _make_environ
9087

9188

9289
@pytest.fixture
9390
def json_request_environ(fake_environ):
9491
"""Create a JSON POST request environ."""
9592
import json
96-
93+
9794
data = {"key": "value", "number": 42}
98-
body = json.dumps(data).encode('utf-8')
99-
95+
body = json.dumps(data).encode("utf-8")
96+
10097
return fake_environ(
101-
method='POST',
102-
path='/api/test',
103-
content_type='application/json',
98+
method="POST",
99+
path="/api/test",
100+
content_type="application/json",
104101
content_length=len(body),
105-
body=body
102+
body=body,
106103
)
107104

108105

109106
@pytest.fixture
110107
def form_request_environ(fake_environ):
111108
"""Create a form POST request environ."""
112-
body = b'username=testuser&email=test@example.com'
113-
109+
body = b"username=testuser&email=test@example.com"
110+
114111
return fake_environ(
115-
method='POST',
116-
path='/form',
117-
content_type='application/x-www-form-urlencoded',
112+
method="POST",
113+
path="/form",
114+
content_type="application/x-www-form-urlencoded",
118115
content_length=len(body),
119-
body=body
116+
body=body,
120117
)
121118

122119

123120
@pytest.fixture
124121
def file_upload_environ(fake_environ):
125122
"""Create a file upload request environ."""
126-
boundary = '----WebKitFormBoundary'
123+
boundary = "----WebKitFormBoundary"
127124
body = (
128-
f'--{boundary}\r\n'
125+
f"--{boundary}\r\n"
129126
f'Content-Disposition: form-data; name="file"; filename="test.txt"\r\n'
130-
f'Content-Type: text/plain\r\n'
131-
f'\r\n'
132-
f'test file content\r\n'
133-
f'--{boundary}--\r\n'
134-
).encode('utf-8')
135-
127+
f"Content-Type: text/plain\r\n"
128+
f"\r\n"
129+
f"test file content\r\n"
130+
f"--{boundary}--\r\n"
131+
).encode("utf-8")
132+
136133
return fake_environ(
137-
method='POST',
138-
path='/upload',
139-
content_type=f'multipart/form-data; boundary={boundary}',
134+
method="POST",
135+
path="/upload",
136+
content_type=f"multipart/form-data; boundary={boundary}",
140137
content_length=len(body),
141-
body=body
138+
body=body,
142139
)
143140

144141

@@ -149,23 +146,12 @@ def pytest_configure(config):
149146
"markers", "unit: Unit tests that test individual components"
150147
)
151148
config.addinivalue_line(
152-
"markers", "integration: Integration tests that test multiple components together"
153-
)
154-
config.addinivalue_line(
155-
"markers", "slow: Tests that take a long time to run"
156-
)
157-
config.addinivalue_line(
158-
"markers", "asyncio: Async tests"
159-
)
160-
config.addinivalue_line(
161-
"markers", "forms: Form validation tests"
162-
)
163-
config.addinivalue_line(
164-
"markers", "routing: Routing tests"
165-
)
166-
config.addinivalue_line(
167-
"markers", "database: Database tests"
168-
)
169-
config.addinivalue_line(
170-
"markers", "security: Security tests"
149+
"markers",
150+
"integration: Integration tests that test multiple components together",
171151
)
152+
config.addinivalue_line("markers", "slow: Tests that take a long time to run")
153+
config.addinivalue_line("markers", "asyncio: Async tests")
154+
config.addinivalue_line("markers", "forms: Form validation tests")
155+
config.addinivalue_line("markers", "routing: Routing tests")
156+
config.addinivalue_line("markers", "database: Database tests")
157+
config.addinivalue_line("markers", "security: Security tests")

Tests/script_install_required_modules_for_test.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,34 @@
33
import importlib
44
import os
55

6+
67
def install_module(module_name):
78
"""Install a Python module using pip."""
8-
9+
910
pip = ""
10-
if os.name == 'nt':
11+
if os.name == "nt":
1112
pip = "pip"
1213
else:
1314
pip = "pip3"
14-
15+
1516
try:
1617
subprocess.check_call([sys.executable, "-m", pip, "install", module_name])
1718
return True
1819
except subprocess.CalledProcessError as e:
1920
print(f"[ERROR] Failed to install module {module_name}: {e}")
20-
21+
2122
return False
22-
23+
24+
2325
def check_module_installed(module_name):
2426
"""Check if a Python module is installed."""
2527
try:
2628
importlib.import_module(module_name)
2729
return True
2830
except ImportError:
2931
return False
30-
32+
33+
3134
if __name__ == "__main__":
3235
required_modules = [
3336
"starlette",
@@ -36,20 +39,22 @@ def check_module_installed(module_name):
3639
"flask",
3740
"django",
3841
]
39-
42+
4043
for module in required_modules:
4144
if not check_module_installed(module):
4245
print(f"[INFO] Module {module} is not installed. Attempting to install...")
43-
46+
4447
if install_module(module):
4548
print(f"[INFO] Rechecking installation of module: {module}")
4649
else:
4750
print(f"[ERROR] Installation attempt for module {module} failed.")
4851
continue
49-
52+
5053
if not check_module_installed(module):
51-
print(f"[ERROR] Module {module} could not be installed. Please install it manually.")
52-
54+
print(
55+
f"[ERROR] Module {module} could not be installed. Please install it manually."
56+
)
57+
5358
print(f"[INFO] Module {module} is installed.")
54-
59+
5560
print("[INFO] All required modules are installed.")

0 commit comments

Comments
 (0)