Skip to content

Commit 28b35e5

Browse files
fix some of linter warnings (#238)
1 parent 86aef33 commit 28b35e5

File tree

12 files changed

+83
-76
lines changed

12 files changed

+83
-76
lines changed

src/extensions/score_layout/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def update_config(app: Sphinx, _config: Any):
4747
# Docs-as-code is the current module
4848
module = "_main"
4949
app.config.html_static_path.append(str(Path(r) / module / "src/assets"))
50-
app.config.needs_flow_configs = {
51-
"score_config": f"!include {Path(r) / module / 'src/assets/puml-theme-score.puml'}"
52-
}
50+
51+
puml = Path(r) / module / "src/assets/puml-theme-score.puml"
52+
app.config.needs_flow_configs = {"score_config": f"!include {puml}"}
5353

5454
app.add_css_file("css/score.css", priority=500)
5555
app.add_css_file("css/score_needs.css", priority=500)

src/extensions/score_metamodel/tests/test_check_options.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
from unittest.mock import Mock
1616

1717
import pytest
18+
from attribute_plugin import add_test_properties
1819
from score_metamodel.checks.check_options import (
1920
check_extra_options,
2021
check_options,
2122
)
2223
from score_metamodel.tests import fake_check_logger, need
2324
from sphinx.application import Sphinx
2425

25-
from attribute_plugin import add_test_properties
26-
2726

2827
class NeedTypeDict(TypedDict, total=False):
2928
directive: str

src/extensions/score_metamodel/tests/test_metamodel__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
import pytest
14+
from attribute_plugin import add_test_properties
1415

1516
from src.extensions.score_metamodel.__init__ import (
1617
graph_checks,
1718
local_checks,
1819
parse_checks_filter,
1920
)
2021

21-
from attribute_plugin import add_test_properties
22-
2322

2423
def dummy_local_check(app, need, log):
2524
pass

src/extensions/score_source_code_linker/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ def inject_links_into_needs(app: Sphinx, env: BuildEnvironment) -> None:
357357
# TODO: print github annotations as in https://github.com/eclipse-score/bazel_registry/blob/7423b9996a45dd0a9ec868e06a970330ee71cf4f/tools/verify_semver_compatibility_level.py#L126-L129
358358
for n in source_code_links.links.CodeLinks:
359359
LOGGER.warning(
360-
f"{n.file}:{n.line}: Could not find {source_code_links.need} in documentation [CODE LINK]",
360+
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
361+
"in documentation [CODE LINK]",
361362
type="score_source_code_linker",
362363
)
363364
for n in source_code_links.links.TestLinks:
364365
LOGGER.warning(
365-
f"{n.file}:{n.line}: Could not find {source_code_links.need} in documentation [TEST LINK]",
366+
f"{n.file}:{n.line}: Could not find {source_code_links.need} "
367+
"in documentation [TEST LINK]",
366368
type="score_source_code_linker",
367369
)
368370
continue

src/extensions/score_source_code_linker/need_source_links.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
"""
14-
This file defines NeedSourceLinks as well as SourceCodeLinks.
15-
Both datatypes are used in the 'grouped cache' JSON that contains 'CodeLinks' and 'TestLinks'
16-
It also defines a decoder and encoder for SourceCodeLinks to enable JSON read/write
14+
This file defines NeedSourceLinks as well as SourceCodeLinks. Both datatypes are used in
15+
the 'grouped cache' JSON that contains 'CodeLinks' and 'TestLinks' It also defines a
16+
decoder and encoder for SourceCodeLinks to enable JSON read/write
1717
"""
1818

1919
# req-Id: tool_req__docs_test_link_testcase
@@ -56,9 +56,9 @@ class SourceCodeLinks:
5656

5757
class SourceCodeLinks_JSON_Encoder(json.JSONEncoder):
5858
def default(self, o: object):
59-
if isinstance(o, (SourceCodeLinks, NeedSourceLinks)):
59+
if isinstance(o, SourceCodeLinks | NeedSourceLinks):
6060
return asdict(o)
61-
if isinstance(o, (NeedLink, DataForTestLink)):
61+
if isinstance(o, NeedLink | DataForTestLink):
6262
return asdict(o)
6363
if isinstance(o, Path):
6464
return str(o)
@@ -81,7 +81,8 @@ def SourceCodeLinks_JSON_Decoder(d: dict[str, Any]) -> SourceCodeLinks | dict[st
8181
def store_source_code_links_combined_json(
8282
file: Path, source_code_links: list[SourceCodeLinks]
8383
):
84-
# After `rm -rf _build` or on clean builds the directory does not exist, so we need to create it
84+
# After `rm -rf _build` or on clean builds the directory does not exist, so we need
85+
# to create it
8586
file.parent.mkdir(exist_ok=True)
8687
with open(file, "w") as f:
8788
json.dump(
@@ -99,9 +100,11 @@ def load_source_code_links_combined_json(file: Path) -> list[SourceCodeLinks]:
99100
object_hook=SourceCodeLinks_JSON_Decoder,
100101
)
101102
assert isinstance(links, list), (
102-
"The combined source code linker links should be a list of SourceCodeLinks objects."
103+
"The combined source code linker links should be "
104+
"a list of SourceCodeLinks objects."
103105
)
104106
assert all(isinstance(link, SourceCodeLinks) for link in links), (
105-
"All items in combined_source_code_linker_cache should be SourceCodeLinks objects."
107+
"All items in combined_source_code_linker_cache should be "
108+
"SourceCodeLinks objects."
106109
)
107110
return links

src/extensions/score_source_code_linker/testlink.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ def DataOfTestCase_JSON_Decoder(d: dict[str, Any]) -> DataOfTestCase | dict[str,
194194

195195
def store_test_xml_parsed_json(file: Path, testlist: list[DataForTestLink]):
196196
"""
197-
TestCases that are 'skipped' do not have properties, therefore they will NOT be saved/transformed
198-
to TestLinks.
197+
TestCases that are 'skipped' do not have properties, therefore they will NOT be
198+
saved/transformed to TestLinks.
199199
"""
200-
# After `rm -rf _build` or on clean builds the directory does not exist, so we need to create it
200+
# After `rm -rf _build` or on clean builds the directory does not exist, so we need
201+
# to create it
201202
file.parent.mkdir(exist_ok=True)
202203
with open(file, "w") as f:
203204
json.dump(
@@ -224,7 +225,8 @@ def load_test_xml_parsed_json(file: Path) -> list[DataForTestLink]:
224225

225226

226227
def store_data_of_test_case_json(file: Path, testneeds: list[DataOfTestCase]):
227-
# After `rm -rf _build` or on clean builds the directory does not exist, so we need to create it
228+
# After `rm -rf _build` or on clean builds the directory does not exist, so we need
229+
# to create it
228230
file.parent.mkdir(exist_ok=True)
229231
with open(file, "w") as f:
230232
json.dump(

src/extensions/score_source_code_linker/tests/test_codelink.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from typing import Any
2020

2121
import pytest
22+
from attribute_plugin import add_test_properties
2223
from sphinx_needs.data import NeedsMutable
2324

2425
from src.extensions.score_metamodel.tests import need as test_need
25-
from attribute_plugin import add_test_properties
2626

2727
# Import the module under test
2828
# Note: You'll need to adjust these imports based on your actual module structure
@@ -38,8 +38,6 @@
3838
)
3939
from src.helper_lib import (
4040
get_current_git_hash,
41-
get_github_repo_info,
42-
parse_remote_git_output,
4341
)
4442
from src.helper_lib.additional_functions import get_github_link
4543

src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13+
import contextlib
1314
import json
1415
import os
1516
import shutil
@@ -46,7 +47,7 @@ def sphinx_base_dir(tmp_path_factory: TempPathFactory) -> Path:
4647

4748

4849
@pytest.fixture()
49-
def git_repo_setup(sphinx_base_dir) -> Path:
50+
def git_repo_setup(sphinx_base_dir: Path) -> Path:
5051
"""Creating git repo, to make testing possible"""
5152

5253
repo_path = sphinx_base_dir
@@ -68,7 +69,7 @@ def git_repo_setup(sphinx_base_dir) -> Path:
6869

6970

7071
@pytest.fixture()
71-
def create_demo_files(sphinx_base_dir, git_repo_setup):
72+
def create_demo_files(sphinx_base_dir: Path, git_repo_setup):
7273
repo_path = sphinx_base_dir
7374

7475
# Create some source files with requirement IDs
@@ -141,7 +142,7 @@ def make_codelink_source_2():
141142
return (
142143
"""
143144
# Another implementation file
144-
# Though we should make sure this
145+
# Though we should make sure this
145146
# is at a different line than the other ID
146147
#"""
147148
+ """ req-Id: TREQ_ID_1
@@ -214,7 +215,7 @@ def construct_gh_url() -> str:
214215

215216
@pytest.fixture()
216217
def sphinx_app_setup(
217-
sphinx_base_dir, create_demo_files, git_repo_setup
218+
sphinx_base_dir: Path, create_demo_files, git_repo_setup
218219
) -> Callable[[], SphinxTestApp]:
219220
def _create_app():
220221
base_dir = sphinx_base_dir
@@ -223,11 +224,9 @@ def _create_app():
223224
# CRITICAL: Change to a directory that exists and is accessible
224225
# This fixes the "no such file or directory" error in Bazel
225226
original_cwd = None
226-
try:
227+
# Current working directory doesn't exist, which is the problem
228+
with contextlib.suppress(FileNotFoundError):
227229
original_cwd = os.getcwd()
228-
except FileNotFoundError:
229-
# Current working directory doesn't exist, which is the problem
230-
pass
231230

232231
# Change to the base_dir before creating SphinxTestApp
233232
os.chdir(base_dir)
@@ -243,11 +242,9 @@ def _create_app():
243242
finally:
244243
# Try to restore original directory, but don't fail if it doesn't exist
245244
if original_cwd is not None:
246-
try:
245+
# Original directory might not exist anymore in Bazel sandbox
246+
with contextlib.suppress(FileNotFoundError, OSError):
247247
os.chdir(original_cwd)
248-
except (FileNotFoundError, OSError):
249-
# Original directory might not exist anymore in Bazel sandbox
250-
pass
251248

252249
return _create_app
253250

@@ -302,8 +299,7 @@ def basic_needs():
302299

303300

304301
@pytest.fixture()
305-
def example_source_link_text_all_ok(sphinx_base_dir):
306-
repo_path = sphinx_base_dir
302+
def example_source_link_text_all_ok(sphinx_base_dir: Path):
307303
return {
308304
"TREQ_ID_1": [
309305
NeedLink(
@@ -334,8 +330,7 @@ def example_source_link_text_all_ok(sphinx_base_dir):
334330

335331

336332
@pytest.fixture()
337-
def example_test_link_text_all_ok(sphinx_base_dir):
338-
repo_path = sphinx_base_dir
333+
def example_test_link_text_all_ok(sphinx_base_dir: Path):
339334
return {
340335
"TREQ_ID_1": [
341336
DataForTestLink(
@@ -392,8 +387,7 @@ def example_test_link_text_all_ok(sphinx_base_dir):
392387

393388

394389
@pytest.fixture()
395-
def example_source_link_text_non_existent(sphinx_base_dir):
396-
repo_path = sphinx_base_dir
390+
def example_source_link_text_non_existent(sphinx_base_dir: Path):
397391
return [
398392
{
399393
"TREQ_ID_200": [
@@ -409,11 +403,11 @@ def example_source_link_text_non_existent(sphinx_base_dir):
409403
]
410404

411405

412-
def make_source_link(needlinks):
406+
def make_source_link(needlinks: list[NeedLink]):
413407
return ", ".join(f"{get_github_link(n)}<>{n.file}:{n.line}" for n in needlinks)
414408

415409

416-
def make_test_link(testlinks):
410+
def make_test_link(testlinks: list[DataForTestLink]):
417411
return ", ".join(f"{get_github_link(n)}<>{n.name}" for n in testlinks)
418412

419413

@@ -424,12 +418,14 @@ def compare_json_files(file1: Path, expected_file: Path, object_hook):
424418
with open(expected_file) as f2:
425419
json2 = json.load(f2, object_hook=object_hook)
426420
assert len(json1) == len(json2), (
427-
f"{file1}'s lenth are not the same as in the golden file lenght. Len of{file1}: {len(json1)}. Len of Golden File: {len(json2)}"
421+
f"{file1}'s lenth are not the same as in the golden file lenght. "
422+
f"Len of{file1}: {len(json1)}. Len of Golden File: {len(json2)}"
428423
)
429424
c1 = Counter(n for n in json1)
430425
c2 = Counter(n for n in json2)
431426
assert c1 == c2, (
432-
f"Testfile does not have same needs as golden file. Testfile: {c1}\nGoldenFile: {c2}"
427+
f"Testfile does not have same needs as golden file. "
428+
f"Testfile: {c1}\nGoldenFile: {c2}"
433429
)
434430

435431

@@ -441,7 +437,8 @@ def compare_grouped_json_files(file1: Path, golden_file: Path):
441437
json2 = json.load(f2, object_hook=SourceCodeLinks_TEST_JSON_Decoder)
442438

443439
assert len(json1) == len(json2), (
444-
f"Input & Expected have different Lenghts. Input: {file1}: {len(json1)}, Expected: {golden_file}: {len(json2)}"
440+
"Input & Expected have different Lenghts. "
441+
f"Input: {file1}: {len(json1)}, Expected: {golden_file}: {len(json2)}"
445442
)
446443

447444
json1_sorted = sorted(json1, key=lambda x: x.need)
@@ -468,11 +465,14 @@ def compare_grouped_json_files(file1: Path, golden_file: Path):
468465
)
469466

470467

468+
@pytest.mark.skip(
469+
"Flaky test, see https://github.com/eclipse-score/docs-as-code/issues/226"
470+
)
471471
def test_source_link_integration_ok(
472472
sphinx_app_setup: Callable[[], SphinxTestApp],
473-
example_source_link_text_all_ok: dict[str, list[str]],
474-
example_test_link_text_all_ok: dict[str, list[str]],
475-
sphinx_base_dir,
473+
example_source_link_text_all_ok: dict[str, list[NeedLink]],
474+
example_test_link_text_all_ok: dict[str, list[DataForTestLink]],
475+
sphinx_base_dir: Path,
476476
git_repo_setup,
477477
create_demo_files,
478478
):
@@ -536,7 +536,7 @@ def test_source_link_integration_ok(
536536
def test_source_link_integration_non_existent_id(
537537
sphinx_app_setup: Callable[[], SphinxTestApp],
538538
example_source_link_text_non_existent: dict[str, list[str]],
539-
sphinx_base_dir,
539+
sphinx_base_dir: Path,
540540
git_repo_setup,
541541
create_demo_files,
542542
):

src/extensions/score_source_code_linker/tests/test_testlink.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import json
1414
from pathlib import Path
1515

16+
from attribute_plugin import add_test_properties
17+
1618
from src.extensions.score_source_code_linker.testlink import (
1719
DataForTestLink,
1820
DataForTestLink_JSON_Decoder,
@@ -21,7 +23,6 @@
2123
load_test_xml_parsed_json,
2224
store_test_xml_parsed_json,
2325
)
24-
from attribute_plugin import add_test_properties
2526

2627

2728
@add_test_properties(
@@ -72,8 +73,8 @@ def test_decoder_ignores_irrelevant_dicts():
7273
)
7374
def test_clean_text_removes_ansi_and_html_unescapes():
7475
"""
75-
Test if text clean works as intended.
76-
It should remove ANSI color & text styles, as well as convert HTML things back to Chars
76+
Test if text clean works as intended. It should remove ANSI color & text styles, as
77+
well as convert HTML things back to Chars
7778
"""
7879
raw = "\x1b[31m&lt;b&gt;Warning&lt;/b&gt;\x1b[0m\nExtra line"
7980
cleaned = DataOfTestCase.clean_text(raw)
@@ -119,7 +120,7 @@ def test_testcaseneed_to_dict_multiple_links():
119120
test_type="requirements-based",
120121
derivation_technique="requirements-analysis",
121122
)
122-
def test_store_and_load_testlinks_roundtrip(tmp_path):
123+
def test_store_and_load_testlinks_roundtrip(tmp_path: Path):
123124
"""Ensure that Encode/Decode is reversible"""
124125
file = tmp_path / "testlinks.json"
125126

0 commit comments

Comments
 (0)