Skip to content

Commit

Permalink
Apply Black to temporal modules (OSGeo#1388)
Browse files Browse the repository at this point in the history
This applies Black 20.8b1 to all temporal modules and their tests. Enable in CI.
Uses: black --target-version=py36

Add Flake8 settings for Black. Remove Flake8 whitespace ignores except line length. Add per-file-ignores.
  • Loading branch information
wenzeslaus authored Feb 21, 2021
1 parent 1aab3bb commit feff8e3
Show file tree
Hide file tree
Showing 84 changed files with 5,463 additions and 2,884 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ exclude = '''
| gui
| imagery
| lib/gis
| temporal
| raster
| vector
| docker/testdata/test_grass_session.py
Expand Down
43 changes: 16 additions & 27 deletions temporal/.flake8
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
[flake8]
ignore =
F841, # local variable 'column' is assigned to but never used
F821, # undefined name '_'
E265, # block comment should start with '# '
E266, # too many leading '#' for block comment
E502, # the backslash is redundant between brackets
W291, # trailing whitespace
W293, # blank line contains whitespace
W391, # blank line at end of file
W504, # line break after binary operator
E117, # over-indented
E125, # continuation line with same indent as next logical line
E126, # continuation line over-indented for hanging indent
E127, # continuation line over-indented for visual indent
E128, # continuation line under-indented for visual indent
E129, # visually indented line with same indent as next logical line
E222, # multiple spaces after operator
E225, # missing whitespace around operator
E226, # missing whitespace around arithmetic operator
E231, # missing whitespace after ','
E241, # multiple spaces after ','
E251, # unexpected spaces around keyword / parameter equals
E271, # multiple spaces after keyword
E302, # expected 2 blank lines, found 1
E303, # too many blank lines (2)
E305, # expected 2 blank lines after class or function definition, found 1
E501, # line too long (179 > 150 characters)

E203, # whitespace before ':' (Black)
W503, # line break before binary operator (Black)
E501, # line too long (179 > 150 characters)

per-file-ignores =
# local variable 'column' is assigned to but never used
t.rast.to.vect/t.rast.to.vect.py: F841
# local variable 'stdstype' is assigned to but never used
t.vect.algebra/t.vect.algebra.py: F841
# ## used (##% key: r etc)
# local variable 'map_list' is assigned to but never used
t.rast.what/t.rast.what.py: E265, E266, F841

max-line-length = 88
exclude =
.git,
Expand All @@ -41,3 +27,6 @@ exclude =
ctypes,
pydispatch,
testsuite,

builtins =
_
124 changes: 72 additions & 52 deletions temporal/t.connect/testsuite/test_distr_tgis_db_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
class TestRasterExtraction(TestCase):

mapsets_to_remove = []
outfile = 'rastlist.txt'
gisenv = SimpleModule('g.gisenv', get='MAPSET')
outfile = "rastlist.txt"
gisenv = SimpleModule("g.gisenv", get="MAPSET")
TestCase.runModule(gisenv, expecting_stdout=True)
old_mapset = gisenv.outputs.stdout.strip()

Expand All @@ -29,31 +29,43 @@ def setUpClass(cls):
mapset_name = "test%i" % i
cls.runModule("g.mapset", flags="c", mapset=mapset_name)
cls.mapsets_to_remove.append(mapset_name)
cls.runModule("g.region", s=0, n=80,
w=0, e=120, b=0, t=50, res=10, res3=10)
cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)
cls.runModule("t.connect", flags="d")
cls.runModule("t.info", flags="d")
cls.runModule("r.mapcalc", expression="a1 = 100")
cls.runModule("r.mapcalc", expression="a2 = 200")
cls.runModule("r.mapcalc", expression="a3 = 300")
cls.runModule("t.create", type="strds", temporaltype="absolute",
output="A", title="A test", description="A test")
cls.runModule("t.register", flags="i", type="raster", input="A",
maps="a1,a2,a3",
start="2001-01-01", increment="%i months" % i)
cls.runModule(
"t.create",
type="strds",
temporaltype="absolute",
output="A",
title="A test",
description="A test",
)
cls.runModule(
"t.register",
flags="i",
type="raster",
input="A",
maps="a1,a2,a3",
start="2001-01-01",
increment="%i months" % i,
)

# Add the new mapsets to the search path
for mapset in cls.mapsets_to_remove:
cls.runModule("g.mapset", mapset=mapset)
cls.runModule("g.mapsets", operation="add", mapset=','.join(cls.mapsets_to_remove))

cls.runModule(
"g.mapsets", operation="add", mapset=",".join(cls.mapsets_to_remove)
)

@classmethod
def tearDownClass(cls):
gisenv = SimpleModule('g.gisenv', get='GISDBASE')
gisenv = SimpleModule("g.gisenv", get="GISDBASE")
cls.runModule(gisenv, expecting_stdout=True)
gisdbase = gisenv.outputs.stdout.strip()
gisenv = SimpleModule('g.gisenv', get='LOCATION_NAME')
gisenv = SimpleModule("g.gisenv", get="LOCATION_NAME")
cls.runModule(gisenv, expecting_stdout=True)
location = gisenv.outputs.stdout.strip()
cls.runModule("g.mapset", mapset=cls.old_mapset)
Expand All @@ -72,9 +84,12 @@ def test_tlist(self):
A|test6|2001-01-01 00:00:00|2002-07-01 00:00:00|3"""

t_list = SimpleModule(
"t.list", quiet=True,
"t.list",
quiet=True,
columns=["name", "mapset,start_time", "end_time", "number_of_maps"],
type="strds", where='name = "A"')
type="strds",
where='name = "A"',
)
self.assertModule(t_list)

out = t_list.outputs["stdout"].value
Expand All @@ -83,16 +98,20 @@ def test_tlist(self):
self.assertEqual(a.strip(), b.strip())

t_list = SimpleModule(
"t.list", quiet=True,
"t.list",
quiet=True,
columns=["name", "mapset,start_time", "end_time", "number_of_maps"],
type="strds", where='name = "A"', output=self.outfile)
type="strds",
where='name = "A"',
output=self.outfile,
)
self.assertModule(t_list)
self.assertFileExists(self.outfile)
with open(self.outfile, 'r') as f:
with open(self.outfile, "r") as f:
read_data = f.read()
for a, b in zip(list_string.split("\n"), read_data.split("\n")):
self.assertEqual(a.strip(), b.strip())
#self.assertLooksLike(reference=read_data, actual=list_string)
# self.assertLooksLike(reference=read_data, actual=list_string)
if os.path.isfile(self.outfile):
os.remove(self.outfile)

Expand All @@ -103,8 +122,7 @@ def test_trast_list(self):
a2|test1|2001-02-01 00:00:00|2001-03-01 00:00:00
a3|test1|2001-03-01 00:00:00|2001-04-01 00:00:00"""

trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test1")
trast_list = SimpleModule("t.rast.list", quiet=True, flags="u", input="A@test1")
self.assertModule(trast_list)

out = trast_list.outputs["stdout"].value
Expand All @@ -116,8 +134,7 @@ def test_trast_list(self):
a2|test2|2001-03-01 00:00:00|2001-05-01 00:00:00
a3|test2|2001-05-01 00:00:00|2001-07-01 00:00:00"""

trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test2")
trast_list = SimpleModule("t.rast.list", quiet=True, flags="u", input="A@test2")
self.assertModule(trast_list)

out = trast_list.outputs["stdout"].value
Expand All @@ -129,8 +146,7 @@ def test_trast_list(self):
a2|test3|2001-04-01 00:00:00|2001-07-01 00:00:00
a3|test3|2001-07-01 00:00:00|2001-10-01 00:00:00"""

trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test3")
trast_list = SimpleModule("t.rast.list", quiet=True, flags="u", input="A@test3")
self.assertModule(trast_list)

out = trast_list.outputs["stdout"].value
Expand All @@ -142,8 +158,7 @@ def test_trast_list(self):
a2|test4|2001-05-01 00:00:00|2001-09-01 00:00:00
a3|test4|2001-09-01 00:00:00|2002-01-01 00:00:00"""

trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test4")
trast_list = SimpleModule("t.rast.list", quiet=True, flags="u", input="A@test4")
self.assertModule(trast_list)

out = trast_list.outputs["stdout"].value
Expand All @@ -155,20 +170,20 @@ def test_trast_list(self):
a2|test5|2001-06-01 00:00:00|2001-11-01 00:00:00
a3|test5|2001-11-01 00:00:00|2002-04-01 00:00:00"""

trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test5")
trast_list = SimpleModule("t.rast.list", quiet=True, flags="u", input="A@test5")
self.assertModule(trast_list)

out = trast_list.outputs["stdout"].value

for a, b in zip(list_string.split("\n"), out.split("\n")):
self.assertEqual(a.strip(), b.strip())

trast_list = SimpleModule("t.rast.list", quiet=True, flags="u",
input="A@test5", output=self.outfile)
trast_list = SimpleModule(
"t.rast.list", quiet=True, flags="u", input="A@test5", output=self.outfile
)
self.assertModule(trast_list)
self.assertFileExists(self.outfile)
with open(self.outfile, 'r') as f:
with open(self.outfile, "r") as f:
read_data = f.read()
for a, b in zip(list_string.split("\n"), read_data.split("\n")):
self.assertEqual(a.strip(), b.strip())
Expand All @@ -186,7 +201,8 @@ def test_strds_info(self):

info = SimpleModule("t.info", flags="g", input="A@test1")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

self.runModule("g.mapset", mapset="test3")
tinfo_string = """id=A@test2
Expand All @@ -198,7 +214,8 @@ def test_strds_info(self):

info = SimpleModule("t.info", flags="g", input="A@test2")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

self.runModule("g.mapset", mapset="test2")
tinfo_string = """id=A@test3
Expand All @@ -210,7 +227,8 @@ def test_strds_info(self):

info = SimpleModule("t.info", flags="g", input="A@test3")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

self.runModule("g.mapset", mapset="test1")
tinfo_string = """id=A@test4
Expand All @@ -222,7 +240,8 @@ def test_strds_info(self):

info = SimpleModule("t.info", flags="g", input="A@test4")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

tinfo_string = """id=A@test5
name=A
Expand All @@ -233,7 +252,8 @@ def test_strds_info(self):

info = SimpleModule("t.info", flags="g", input="A@test5")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

def test_raster_info(self):
self.runModule("g.mapset", mapset="test3")
Expand All @@ -244,10 +264,10 @@ def test_raster_info(self):
start_time='2001-01-01 00:00:00'
end_time='2001-02-01 00:00:00'"""

info = SimpleModule(
"t.info", flags="g", type="raster", input="a1@test1")
info = SimpleModule("t.info", flags="g", type="raster", input="a1@test1")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

tinfo_string = """id=a1@test2
name=a1
Expand All @@ -256,10 +276,10 @@ def test_raster_info(self):
start_time='2001-01-01 00:00:00'
end_time='2001-03-01 00:00:00'"""

info = SimpleModule(
"t.info", flags="g", type="raster", input="a1@test2")
info = SimpleModule("t.info", flags="g", type="raster", input="a1@test2")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

tinfo_string = """id=a1@test3
name=a1
Expand All @@ -268,10 +288,10 @@ def test_raster_info(self):
start_time='2001-01-01 00:00:00'
end_time='2001-04-01 00:00:00'"""

info = SimpleModule(
"t.info", flags="g", type="raster", input="a1@test3")
info = SimpleModule("t.info", flags="g", type="raster", input="a1@test3")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

tinfo_string = """id=a1@test4
name=a1
Expand All @@ -280,10 +300,10 @@ def test_raster_info(self):
start_time='2001-01-01 00:00:00'
end_time='2001-05-01 00:00:00'"""

info = SimpleModule(
"t.info", flags="g", type="raster", input="a1@test4")
info = SimpleModule("t.info", flags="g", type="raster", input="a1@test4")
self.assertModuleKeyValue(
module=info, reference=tinfo_string, precision=2, sep="=")
module=info, reference=tinfo_string, precision=2, sep="="
)

tinfo_string = """id=a1@test5
name=a1
Expand All @@ -292,10 +312,10 @@ def test_raster_info(self):
start_time='2001-01-01 00:00:00'
end_time='2001-06-01 00:00:00'"""

info = SimpleModule(
"t.info", flags="g", type="raster", input="a1@test5")
info = SimpleModule("t.info", flags="g", type="raster", input="a1@test5")


if __name__ == '__main__':
if __name__ == "__main__":
from grass.gunittest.main import test

test()
Loading

0 comments on commit feff8e3

Please sign in to comment.