Skip to content

Commit 9705679

Browse files
committed
Lint fixes
1 parent a798346 commit 9705679

8 files changed

+51
-37
lines changed

pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ lint.select = [
4646
"RUF"
4747
]
4848

49+
[tool.ruff.lint.extend-per-file-ignores]
50+
"utest/*" = [
51+
"S",
52+
"SLF",
53+
"PLR",
54+
"B018"
55+
]
56+
4957
[tool.ruff.lint.mccabe]
5058
max-complexity = 9
5159

tasks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ def lint(ctx):
132132
ruff_cmd.append("--fix")
133133
ruff_cmd.append("./src")
134134
ruff_cmd.append("./tasks.py")
135+
ruff_cmd.append("./utest")
135136
ctx.run(" ".join(ruff_cmd))
136137
print("Run black")
137-
ctx.run("black src/ tasks.py utest/run.py atest/run.py")
138+
ctx.run("black src/ tasks.py utest atest/run.py")
138139
print("Run tidy")
139140
print(f"Lint Robot files {'in ci' if in_ci else ''}")
140141
command = [

utest/run.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@
22
import argparse
33
import platform
44
import sys
5-
from os.path import abspath, dirname, join
5+
from pathlib import Path
66

77
import pytest
88
from robot.version import VERSION as RF_VERSION
99

10-
curdir = dirname(abspath(__file__))
11-
atest_dir = join(curdir, "..", "atest")
10+
curdir = Path(__file__).parent
11+
atest_dir = curdir / ".." / "atest"
1212
python_version = platform.python_version()
13-
xunit_report = join(
14-
atest_dir,
15-
"results",
16-
"xunit-python-{}-robot{}.xml".format(python_version, RF_VERSION),
17-
)
18-
src = join(curdir, "..", "src")
13+
xunit_report = atest_dir / "results" / f"xunit-python-{python_version}-robot{RF_VERSION}.xml"
14+
src = curdir / ".." / "src"
1915
sys.path.insert(0, src)
2016
sys.path.insert(0, atest_dir)
21-
helpers = join(curdir, "helpers")
17+
helpers = curdir / "helpers"
2218
sys.path.append(helpers)
2319

2420
parser = argparse.ArgumentParser()

utest/test_get_keyword_source.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import inspect
2-
from os import path
2+
from pathlib import Path
33

44
import pytest
55
from DynamicLibrary import DynamicLibrary
@@ -18,23 +18,26 @@ def lib_types():
1818

1919

2020
@pytest.fixture(scope="module")
21-
def cur_dir():
22-
return path.dirname(__file__)
21+
def cur_dir() -> Path:
22+
return Path(__file__).parent
2323

2424

2525
@pytest.fixture(scope="module")
26-
def lib_path(cur_dir):
27-
return path.normpath(path.join(cur_dir, "..", "atest", "DynamicLibrary.py"))
26+
def lib_path(cur_dir) -> Path:
27+
path = cur_dir / ".." / "atest" / "DynamicLibrary.py"
28+
return path.resolve()
2829

2930

3031
@pytest.fixture(scope="module")
31-
def lib_path_components(cur_dir):
32-
return path.normpath(path.join(cur_dir, "..", "atest", "librarycomponents.py"))
32+
def lib_path_components(cur_dir) -> Path:
33+
path = cur_dir / ".." / "atest" / "librarycomponents.py"
34+
return path.resolve()
3335

3436

3537
@pytest.fixture(scope="module")
36-
def lib_path_types(cur_dir):
37-
return path.normpath(path.join(cur_dir, "..", "atest", "DynamicTypesLibrary.py"))
38+
def lib_path_types(cur_dir) -> Path:
39+
path = cur_dir / ".." / "atest" / "DynamicTypesLibrary.py"
40+
return path.resolve()
3841

3942

4043
def test_location_in_main(lib, lib_path):
@@ -60,7 +63,7 @@ def test_location_in_class_custom_keyword_name(lib, lib_path_components):
6063
def test_no_line_number(lib, lib_path, when):
6164
when(lib)._DynamicCore__get_keyword_line(Any()).thenReturn(None)
6265
source = lib.get_keyword_source("keyword_in_main")
63-
assert source == lib_path
66+
assert Path(source) == lib_path
6467

6568

6669
def test_no_path(lib, when):
@@ -90,4 +93,4 @@ def test_error_in_getfile(lib, when):
9093
def test_error_in_line_number(lib, when, lib_path):
9194
when(inspect).getsourcelines(Any()).thenRaise(IOError("Some message"))
9295
source = lib.get_keyword_source("keyword_in_main")
93-
assert source == lib_path
96+
assert Path(source) == lib_path

utest/test_get_keyword_types.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from DynamicTypesAnnotationsLibrary import CustomObject, DynamicTypesAnnotationsLibrary
66
from DynamicTypesLibrary import DynamicTypesLibrary
7-
from lib_future_annotation import lib_future_annotation, Location
7+
from lib_future_annotation import Location, lib_future_annotation
88

99

1010
@pytest.fixture(scope="module")
@@ -80,7 +80,7 @@ def test_keyword_new_type(lib_types):
8080

8181
def test_keyword_return_type(lib_types):
8282
types = lib_types.get_keyword_types("keyword_define_return_type")
83-
assert types == {"arg": str, 'return': Union[List[str], str]}
83+
assert types == {"arg": str, "return": Union[List[str], str]}
8484

8585

8686
def test_keyword_forward_references(lib_types):
@@ -105,7 +105,7 @@ def test_keyword_with_annotation_external_class(lib_types):
105105

106106
def test_keyword_with_annotation_and_default_part2(lib_types):
107107
types = lib_types.get_keyword_types("keyword_default_and_annotation")
108-
assert types == {"arg1": int, "arg2": Union[bool, str], 'return': str}
108+
assert types == {"arg1": int, "arg2": Union[bool, str], "return": str}
109109

110110

111111
def test_keyword_with_robot_types_and_annotations(lib_types):
@@ -205,7 +205,7 @@ def test_kw_with_named_arguments(lib_types: DynamicTypesAnnotationsLibrary):
205205

206206
def test_kw_with_many_named_arguments_with_default(lib_types: DynamicTypesAnnotationsLibrary):
207207
types = lib_types.get_keyword_types("kw_with_many_named_arguments_with_default")
208-
assert types == {'arg2': int}
208+
assert types == {"arg2": int}
209209
types = lib_types.get_keyword_types("kw_with_positional_and_named_arguments_with_defaults")
210210
assert types == {"arg1": int, "arg2": str}
211211
types = lib_types.get_keyword_types("kw_with_positional_and_named_arguments")

utest/test_plugin_api.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from helpers import my_plugin_test
21
import pytest
2+
from helpers import my_plugin_test
33
from robotlibcore import Module, PluginError, PluginParser
44

55

@@ -19,17 +19,17 @@ def test_plugins_string_to_modules(plugin_parser):
1919
result = plugin_parser._string_to_modules("path.to.MyLibrary,path.to.OtherLibrary")
2020
assert result == [
2121
Module("path.to.MyLibrary", [], {}),
22-
Module("path.to.OtherLibrary", [], {})
22+
Module("path.to.OtherLibrary", [], {}),
2323
]
2424
result = plugin_parser._string_to_modules("path.to.MyLibrary , path.to.OtherLibrary")
2525
assert result == [
2626
Module("path.to.MyLibrary", [], {}),
27-
Module("path.to.OtherLibrary", [], {})
27+
Module("path.to.OtherLibrary", [], {}),
2828
]
2929
result = plugin_parser._string_to_modules("path.to.MyLibrary;foo;bar , path.to.OtherLibrary;1")
3030
assert result == [
3131
Module("path.to.MyLibrary", ["foo", "bar"], {}),
32-
Module("path.to.OtherLibrary", ["1"], {})
32+
Module("path.to.OtherLibrary", ["1"], {}),
3333
]
3434
result = plugin_parser._string_to_modules("PluginWithKwArgs.py;kw1=Text1;kw2=Text2")
3535
assert result == [
@@ -52,7 +52,7 @@ def test_parse_plugins_as_list(plugin_parser):
5252
assert len(plugins) == 1
5353
assert isinstance(plugins[0], my_plugin_test.TestClass)
5454
plugins = plugin_parser.parse_plugins(
55-
["helpers.my_plugin_test.TestClass", "helpers.my_plugin_test.TestClassWithBase"]
55+
["helpers.my_plugin_test.TestClass", "helpers.my_plugin_test.TestClassWithBase"],
5656
)
5757
assert len(plugins) == 2
5858
assert isinstance(plugins[0], my_plugin_test.TestClass)
@@ -81,11 +81,11 @@ def test_plugin_python_objects():
8181
class PythonObject:
8282
x = 1
8383
y = 2
84+
8485
python_object = PythonObject()
8586
parser = PluginParser(my_plugin_test.LibraryBase, [python_object])
8687
plugins = parser.parse_plugins("helpers.my_plugin_test.TestPluginWithPythonArgs;4")
8788
assert len(plugins) == 1
8889
plugin = plugins[0]
8990
assert plugin.python_class.x == 1
9091
assert plugin.python_class.y == 2
91-

utest/test_robotlibcore.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import json
2+
23
import pytest
4+
from approvaltests.approvals import verify
35
from DynamicLibrary import DynamicLibrary
46
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
57
from HybridLibrary import HybridLibrary
68
from robotlibcore import HybridCore, NoKeywordFound
7-
from approvaltests.approvals import verify, verify_all
89

910

1011
@pytest.fixture(scope="module")
@@ -17,15 +18,17 @@ def test_keyword_names_hybrid():
1718

1819

1920
def test_keyword_names_dynamic():
20-
verify(json.dumps(DynamicLibrary().get_keyword_names(), indent=4))
21+
verify(json.dumps(DynamicLibrary().get_keyword_names(), indent=4))
22+
2123

2224
def test_dir_dyn_lib():
2325
result = [a for a in dir(DynamicLibrary()) if a[:2] != "__"]
2426
result = json.dumps(result, indent=4)
2527
verify(result)
2628

29+
2730
def test_dir_hubrid_lib():
28-
result = [a for a in dir(HybridLibrary()) if a[:2] != "__"]
31+
result = [a for a in dir(HybridLibrary()) if a[:2] != "__"]
2932
result = json.dumps(result, indent=4)
3033
verify(result)
3134

utest/test_translations.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
2-
import pytest
32

3+
import pytest
44
from SmallLibrary import SmallLibrary
55

66

@@ -9,18 +9,21 @@ def lib():
99
translation = Path(__file__).parent.parent / "atest" / "translation.json"
1010
return SmallLibrary(translation=translation)
1111

12+
1213
def test_invalid_translation():
1314
translation = Path(__file__)
1415
assert SmallLibrary(translation=translation)
1516

17+
1618
def test_translations_names(lib: SmallLibrary):
1719
keywords = lib.keywords_spec
1820
assert "other_name" in keywords
1921
assert "name_changed_again" in keywords
2022

23+
2124
def test_translations_docs(lib: SmallLibrary):
2225
keywords = lib.keywords_spec
2326
kw = keywords["other_name"]
2427
assert kw.documentation == "This is new doc"
2528
kw = keywords["name_changed_again"]
26-
assert kw.documentation == "This is also replaced.\n\nnew line."
29+
assert kw.documentation == "This is also replaced.\n\nnew line."

0 commit comments

Comments
 (0)