Skip to content

Commit b37df12

Browse files
committed
test: Ruff formatting for test code
1 parent 860f5d9 commit b37df12

13 files changed

Lines changed: 37 additions & 40 deletions

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ split-on-trailing-comma = false
505505
"script/*" = ["T20"]
506506

507507
# Allow relative imports within auth and within components
508-
"tests/components/*/*/*" = ["TID252"]
508+
"tests/*" = ["TID252"]
509509
"custom_components/*/*/*" = ["TID252"]
510510

511511
# Temporary

‎tests/conftest.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333

3434
@pytest.fixture(autouse=True)
3535
def folder_setup(tmp_path):
36-
"""Setup the testing session."""
36+
"""Folder setup for testing session."""
3737
directory = tmp_path / TOKEN_LOCATION
3838
directory.mkdir(parents=True, exist_ok=True)
3939

4040

4141
@pytest.fixture(autouse=True)
4242
def token_storage_path_setup(tmp_path):
43-
"""Setup the storage paths."""
43+
"""Storage paths setup."""
4444
tk_path = tmp_path / TOKEN_LOCATION
4545

4646
with patch.object(
@@ -126,7 +126,7 @@ def v1_config_entry(request, hass: HomeAssistant) -> MS365MockConfigEntry:
126126

127127
@pytest.fixture
128128
def base_token(request, tmp_path):
129-
"""Setup a basic token."""
129+
"""Create the Base token."""
130130
perms = BASE_TOKEN_PERMS
131131
if hasattr(request, "param"):
132132
perms = request.param
@@ -135,7 +135,7 @@ def base_token(request, tmp_path):
135135

136136
@pytest.fixture
137137
def legacy_token(tmp_path):
138-
"""Setup a legacy token."""
138+
"""Create a legacy token."""
139139
token = LEGACY_TOKEN
140140
filename = tmp_path / TOKEN_LOCATION / f"{DOMAIN}_{ENTITY_NAME}.token"
141141
with open(filename, "w", encoding="UTF8") as f:

‎tests/const.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"https://login.microsoftonline.com/common/oauth2/v2.0/" + "authorize?client_id="
1616
)
1717
TOKEN_URL_CN21V_ASSERT = (
18-
"https://login.partner.microsoftonline.cn/common/oauth2/v2.0/"
19-
+ "authorize?client_id="
18+
"https://login.partner.microsoftonline.cn/common/oauth2/v2.0/authorize?client_id="
2019
)
2120
STORAGE_LOCATION = "storage"
2221
TOKEN_LOCATION = "storage/tokens"

‎tests/helpers/utils.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def mock_cn21v_token(requests_mock, scope):
4040
)
4141

4242
def _build_file_token(scope):
43-
"""Build a token"""
43+
"""Build a token."""
4444
perms = f"{scope} User.Read email openid profile"
4545
expire = int(time.time() + TOKEN_TIME)
4646
return {
@@ -101,7 +101,7 @@ def _build_file_token(scope):
101101

102102

103103
def build_retrieved_token(scope):
104-
"""Build a token"""
104+
"""Build a token."""
105105
return {
106106
"token_type": "Bearer",
107107
"scope": f"{scope} User.Read profile openid email",
@@ -113,7 +113,7 @@ def build_retrieved_token(scope):
113113

114114

115115
def build_token_url(result, token_url):
116-
"""Build the correct token url"""
116+
"""Build the correct token url."""
117117
state = re.search("state=(.*?)&", result["description_placeholders"]["auth_url"])[1]
118118

119119
return f"{token_url}?{TOKEN_PARAMS.format(state)}"
@@ -137,7 +137,7 @@ def mock_call(
137137
method="get",
138138
tenant_id=None,
139139
):
140-
"""Mock a call"""
140+
"""Mock a call."""
141141
data = load_json(f"O365/{datafile}.json")
142142
if start:
143143
data = data.replace("2020-01-01", start).replace("2020-01-02", end)
@@ -174,17 +174,17 @@ def check_entity_state(
174174
):
175175
"""Check entity state."""
176176
state = hass.states.get(entity_name)
177-
print("*************************** State")
178-
print(state)
179-
print("--- State Attributes")
180-
print(state.attributes)
177+
# print("*************************** State")
178+
# print(state)
179+
# print("--- State Attributes")
180+
# print(state.attributes)
181181
assert state.state == entity_state
182182
if entity_attributes:
183183
if "data" in state.attributes:
184-
print("--- Data Attributes")
185-
print(state.attributes["data"])
186-
print("--- Match Attributes")
187-
print(entity_attributes)
184+
# print("--- Data Attributes")
185+
# print(state.attributes["data"])
186+
# print("--- Match Attributes")
187+
# print(entity_attributes)
188188
assert state.attributes["data"] == entity_attributes
189189
else:
190190
assert state.attributes == entity_attributes
@@ -202,7 +202,7 @@ def utcnow():
202202

203203

204204
def token_setup(tmp_path, infile):
205-
"""Setup a token file"""
205+
"""Create a token file."""
206206
fromfile = TEST_DATA_LOCATION / f"token/{infile}.token"
207207
tofile = tmp_path / TOKEN_LOCATION / f"{DOMAIN}_test.token"
208208
shutil.copy(fromfile, tofile)

‎tests/integration/const_integration.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282

8383
class URL(Enum):
84-
"""List of URLs"""
84+
"""List of URLs."""
8585

8686
OPENID = (
8787
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"
@@ -95,7 +95,7 @@ class URL(Enum):
9595

9696

9797
class CN21VURL(Enum):
98-
"""List of URLs"""
98+
"""List of URLs."""
9999

100100
DISCOVERY = "https://login.microsoftonline.com/common/discovery/instance"
101101
OPENID = "https://login.partner.microsoftonline.cn/common/v2.0/.well-known/openid-configuration"

‎tests/integration/fixtures.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@pytest.fixture(autouse=True)
2525
def yaml_storage_path_setup(tmp_path):
26-
"""Setup the storage paths."""
26+
"""Create the storage paths."""
2727
yml_path = tmp_path / STORAGE_LOCATION / f"{DOMAIN}s_test.yaml"
2828

2929
with patch.object(

‎tests/integration/helpers_integration/mocks.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MS365Mocks:
99
"""Standard mocks."""
1010

1111
def standard_mocks(self, requests_mock):
12-
"""Setup the standard mocks."""
12+
"""Create the standard mocks."""
1313
mock_call(requests_mock, URL.OPENID, "openid")
1414
mock_call(requests_mock, URL.ME, "me")
1515
mock_call(requests_mock, URL.CALENDARS, "calendars")
@@ -42,7 +42,7 @@ def standard_mocks(self, requests_mock):
4242
)
4343

4444
def cn21v_mocks(self, requests_mock, tenant_id="common"):
45-
"""Setup the standard mocks."""
45+
"""Create the standard mocks."""
4646
mock_call(requests_mock, CN21VURL.DISCOVERY, "discovery")
4747
# Mock the /common/ openid config with CN21V-specific URLs.
4848
# MSAL fetches this via the discovery response's tenant_discovery_endpoint.
@@ -59,7 +59,7 @@ def cn21v_mocks(self, requests_mock, tenant_id="common"):
5959
mock_call(requests_mock, CN21VURL.CALENDARS, "calendar3", "calendar3")
6060

6161
def shared_mocks(self, requests_mock):
62-
"""Setup the standard mocks."""
62+
"""Create the standard mocks."""
6363
mock_call(requests_mock, URL.OPENID, "openid")
6464
mock_call(requests_mock, URL.ME, "me")
6565
mock_call(requests_mock, URL.SHARED_CALENDARS, "calendars")
@@ -90,7 +90,7 @@ def shared_mocks(self, requests_mock):
9090
)
9191

9292
def no_events_mocks(self, requests_mock):
93-
"""Setup the standard mocks."""
93+
"""Create the standard mocks."""
9494
_generic_mocks(requests_mock)
9595
mock_call(
9696
requests_mock,
@@ -102,7 +102,7 @@ def no_events_mocks(self, requests_mock):
102102
)
103103

104104
def all_day_event_mocks(self, requests_mock):
105-
"""Setup the standard mocks."""
105+
"""Create the standard mocks."""
106106
_generic_mocks(requests_mock)
107107
mock_call(
108108
requests_mock,
@@ -114,7 +114,7 @@ def all_day_event_mocks(self, requests_mock):
114114
)
115115

116116
def started_event_mocks(self, requests_mock):
117-
"""Setup the standard mocks."""
117+
"""Create the standard mocks."""
118118
_generic_mocks(requests_mock)
119119
mock_call(
120120
requests_mock,
@@ -126,7 +126,7 @@ def started_event_mocks(self, requests_mock):
126126
)
127127

128128
def not_started_event_mocks(self, requests_mock):
129-
"""Setup the standard mocks."""
129+
"""Create the standard mocks."""
130130
_generic_mocks(requests_mock)
131131
mock_call(
132132
requests_mock,

‎tests/integration/helpers_integration/utils_integration.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def yaml_setup(tmp_path, infile):
30-
"""Setup a yaml file"""
30+
"""Create a yaml file."""
3131
fromfile = TEST_DATA_INTEGRATION_LOCATION / f"yaml/{infile}.yaml"
3232
tofile = tmp_path / STORAGE_LOCATION / f"{DOMAIN}s_test.yaml"
3333
shutil.copy(fromfile, tofile)
@@ -37,7 +37,7 @@ async def update_options(
3737
hass: HomeAssistant,
3838
base_config_entry: MS365MockConfigEntry,
3939
) -> None:
40-
"""Test the options flow"""
40+
"""Test the options flow."""
4141

4242
result = await hass.config_entries.options.async_init(base_config_entry.entry_id)
4343
result = await hass.config_entries.options.async_configure(

‎tests/integration/test_config_flow.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def test_options_flow(
4545
setup_base_integration,
4646
base_config_entry: MS365MockConfigEntry,
4747
) -> None:
48-
"""Test the options flow"""
48+
"""Test the options flow."""
4949

5050
result = await hass.config_entries.options.async_init(base_config_entry.entry_id)
5151
await hass.async_block_till_done()

‎tests/integration/test_filemgmt.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ async def test_deleted_file(
8080

8181
check_yaml_file_contents(tmp_path, "ms365_calendars_base")
8282

83-
assert "Calendar deleted from" in caplog.text
83+
assert "Calendar deleted from" in caplog.text

0 commit comments

Comments
 (0)