Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Enable checking for pep8-naming (N) rules with ruff, fix N804, N805 and N813 #4556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gui/wxpython/mapswipe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,15 @@ class _onDone:
we are pasting together 2 rendered images, so
we need to know when both are finished."""

def __init__(self2):
def __init__(self2): # noqa: N805
self2.called = 0

def __call__(self2):
def __call__(self2): # noqa: N805
self2.called += 1
if self2.called == 2:
self2.process()

def process(self2):
def process(self2): # noqa: N805
# create empty white image - needed for line
im = wx.Image(width, height)
im.Replace(0, 0, 0, 255, 255, 255)
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ select = [
"INT", # flake8-gettext (INT)
"ISC", # flake8-implicit-str-concat (ISC)
"LOG", # flake8-logging (LOG)
"N", # pep8-naming (N)
"NPY", # NumPy-specific rules (NPY)
"PERF", # Perflint (PERF)
"PGH", # pygrep-hooks (PGH)
Expand Down Expand Up @@ -145,6 +146,16 @@ ignore = [
"FBT003", # boolean-positional-value-in-call
"I001", # unsorted-imports
"ISC003", # explicit-string-concatenation
"N801", # invalid-class-name
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N806", # non-lowercase-variable-in-function
"N812", # lowercase-imported-as-non-lowercase
"N814", # camelcase-imported-as-constant
"N815", # mixed-case-variable-in-class-scope
"N816", # mixed-case-variable-in-global-scope
"N818", # error-suffix-on-exception-name
"N999", # invalid-module-name
"PERF203", # try-except-in-loop
"PERF401", # manual-list-comprehension
"PERF402", # manual-list-copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class ModulesMeta(type):
def __new__(mcs, name, bases, dict):
def __new__(cls, name, bases, dict):
def gen_test(cmd):
def test(self):
Module(cmd)
Expand All @@ -36,7 +36,7 @@ def test(self):
for cmd in cmds:
test_name = "test__%s" % cmd.replace(".", "_")
dict[test_name] = gen_test(cmd)
return type.__new__(mcs, name, bases, dict)
return type.__new__(cls, name, bases, dict)


class TestModules(TestCase, metaclass=ModulesMeta):
Expand Down
6 changes: 3 additions & 3 deletions python/grass/script/tests/test_script_task.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from grass.script.task import grassTask as gtask
from grass.script.task import grassTask


def test_mapcalc_simple_e_name():
gt = gtask("r.mapcalc.simple")
gt = grassTask("r.mapcalc.simple")
assert gt.get_param("e")["name"] == "e"


def test_mapcalc_simple_expession_name():
gt = gtask("r.mapcalc.simple")
gt = grassTask("r.mapcalc.simple")
assert gt.get_param("expression")["name"] == "expression"
4 changes: 2 additions & 2 deletions raster/r.basins.fill/testsuite/testrbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule("g.remove", flags="f", type="raster", name=cls.output)
def tearDown(self):
self.runModule("g.remove", flags="f", type="raster", name=self.output)

def test_no1(self):
lakes = "lakes"
Expand Down
6 changes: 3 additions & 3 deletions raster/r.series/testsuite/test_r_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def setUpClass(cls):
call_module("r.mapcalc", expression=f"{cls.sum_mapcalc} = {cls.elevation} * 4")

@classmethod
def tearDownClass(self):
self.del_temp_region()
def tearDownClass(cls):
cls.del_temp_region()
call_module(
"g.remove",
flags="f",
type_="raster",
name=self.sum_mapcalc,
name=cls.sum_mapcalc,
)

def tearDown(self):
Expand Down
24 changes: 12 additions & 12 deletions raster/r.terraflow/testsuite/test_r_terraflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ def tearDownClass(cls):
"""!Remove the temporary region"""
cls.del_temp_region()

def setUp(cls):
def setUp(self):
"""Create input data for steady state groundwater flow computation"""
if not os.path.exists(cls.testdir):
os.mkdir(cls.testdir)
if not os.path.exists(self.testdir):
os.mkdir(self.testdir)

def test_univar_mfd(cls):
def test_univar_mfd(self):
# compute a steady state groundwater flow
cls.assertModule(
self.assertModule(
"r.terraflow",
overwrite=True,
verbose=True,
elevation=cls.elevation,
elevation=self.elevation,
filled="terra_flooded",
direction="terra_flowdir",
swatershed="terra_sink",
accumulation="terra_flowaccum",
tci="terra_tci",
directory=cls.testdir,
stats=cls.teststats,
directory=self.testdir,
stats=self.teststats,
)

# Output of r.univar -g
Expand Down Expand Up @@ -111,16 +111,16 @@ def test_univar_mfd(cls):
sum=8341670.75914752"""

# cls.assertRasterFitsUnivar(raster="terra_flooded", reference=terra_flooded_univar, precision=3)
cls.assertRasterFitsUnivar(
self.assertRasterFitsUnivar(
raster="terra_flowdir", reference=terra_flowdir_univar, precision=3
)
cls.assertRasterFitsUnivar(
self.assertRasterFitsUnivar(
raster="terra_sink", reference=terra_sink_univar, precision=3
)
cls.assertRasterFitsUnivar(
self.assertRasterFitsUnivar(
raster="terra_flowaccum", reference=terra_flowaccum_univar, precision=3
)
cls.assertRasterFitsUnivar(
self.assertRasterFitsUnivar(
raster="terra_tci", reference=terra_tci_univar, precision=3
)

Expand Down
4 changes: 2 additions & 2 deletions raster/r.to.vect/testsuite/test_r_to_vect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule("g.remove", type="vector", flags="f", name=cls.output)
def tearDown(self):
self.runModule("g.remove", type="vector", flags="f", name=self.output)

def test_flags(self):
"""Testing flag s"""
Expand Down
4 changes: 2 additions & 2 deletions raster/r.viewshed/testsuite/test_r_viewshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
def tearDown(self):
"""Remove viewshed map after each test method"""
# TODO: eventually, removing maps should be handled through testing framework functions
cls.runModule("g.remove", flags="f", type="raster", name=cls.viewshed)
self.runModule("g.remove", flags="f", type="raster", name=self.viewshed)

def test_limits(self):
"""Test if results is in expected limits"""
Expand Down
4 changes: 2 additions & 2 deletions scripts/r.import/testsuite/test_r_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class TestRImportRegion(TestCase):
def setUpClass(cls):
cls.runModule("g.region", raster="elevation")

def tearDown(cls):
def tearDown(self):
"""Remove imported map after each test method"""
cls.runModule("g.remove", flags="f", type="raster", name=cls.imported)
self.runModule("g.remove", flags="f", type="raster", name=self.imported)

def test_import_estimate(self):
"""Test e flag"""
Expand Down
4 changes: 2 additions & 2 deletions scripts/r.reclass.area/testsuite/testrra.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule("g.remove", type="raster", flags="f", name=cls.output)
def tearDown(self):
self.runModule("g.remove", type="raster", flags="f", name=self.output)

def test_flag_c(self):
"""Testing flag c"""
Expand Down
4 changes: 2 additions & 2 deletions scripts/v.import/testsuite/test_v_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
class TestVImport(TestCase):
imported = "test_v_import_imported"

def tearDown(cls):
def tearDown(self):
"""Remove imported map after each test method"""
cls.runModule("g.remove", flags="f", type="vector", name=cls.imported)
self.runModule("g.remove", flags="f", type="vector", name=self.imported)

def test_import_same_proj_gpkg(self):
"""Import GPKG in same proj, default params"""
Expand Down
4 changes: 2 additions & 2 deletions vector/v.extract/testsuite/test_v_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule("g.remove", flags="f", type="vector", name=cls.output)
def tearDown(self):
self.runModule("g.remove", flags="f", type="vector", name=self.output)

def test_flagd(self):
"""Testing flag d"""
Expand Down
4 changes: 2 additions & 2 deletions vector/v.net/testsuite/test_v_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
class TestVNet(TestCase):
network = "test_vnet"

def tearDown(cls):
def tearDown(self):
"""Remove viewshed map after each test method"""
# TODO: eventually, removing maps should be handled through testing framework functions
cls.runModule("g.remove", flags="f", type="vector", name=cls.network)
self.runModule("g.remove", flags="f", type="vector", name=self.network)

def test_nodes(self):
"""Test"""
Expand Down
6 changes: 3 additions & 3 deletions vector/v.random/testsuite/test_v_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule(
"g.remove", type="vector", flags="f", name=(cls.output, cls.output2)
def tearDown(self):
self.runModule(
"g.remove", type="vector", flags="f", name=(self.output, self.output2)
)

def test_num_points(self):
Expand Down
4 changes: 2 additions & 2 deletions vector/v.select/testsuite/test_v_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TestRasterReport(TestCase):
ainput = "geology"
output = "testvselect"

def tearDown(cls):
cls.runModule("g.remove", type="vector", flags="f", name=cls.output)
def tearDown(self):
self.runModule("g.remove", type="vector", flags="f", name=self.output)

def test_opo(self):
"""Testing operator overlap"""
Expand Down
9 changes: 6 additions & 3 deletions vector/v.to.3d/testsuite/test_vto3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
def tearDown(self):
"""Remove contours map after each test method"""
cls.runModule(
"g.remove", flags="f", type="vector", name=[cls.contours2d, cls.contours3d]
self.runModule(
"g.remove",
flags="f",
type="vector",
name=[self.contours2d, self.contours3d],
)

def test_contours(self):
Expand Down
Loading