From 0e0c86a119d38a06c052c76db9ebddf01f9aba7e Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Sat, 24 Jul 2021 06:09:32 +0200
Subject: [PATCH] [python][black] Autoformat Python tests

---
 .gitlab-ci/default.yml                        |  1 +
 test/python/test_1p.py                        | 56 +++++++++++--------
 test/python/test_explicit_transport_cctpfa.py | 23 +++++---
 test/python/test_fvproblem.py                 |  5 +-
 4 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/.gitlab-ci/default.yml b/.gitlab-ci/default.yml
index db7ffd2359..7b1ced751d 100644
--- a/.gitlab-ci/default.yml
+++ b/.gitlab-ci/default.yml
@@ -38,6 +38,7 @@ python linting:
   # only check the python folder for now (Python code related to bindings)
   # TODO: maybe extend this to the utility scripts?
     - black --check --verbose -- python
+    - black --check --verbose -- test/python
 
 
 select tests:
diff --git a/test/python/test_1p.py b/test/python/test_1p.py
index e4db7b74f5..3edbc3e270 100755
--- a/test/python/test_1p.py
+++ b/test/python/test_1p.py
@@ -16,7 +16,9 @@ try:
     discMethod = sys.argv[1]
     diffMethod = sys.argv[2]
 except IndexError:
-    print("No discretization method and differentiation method given. Defaulting to box and numeric diff.")
+    print(
+        "No discretization method and differentiation method given. Defaulting to box and numeric diff."
+    )
     discMethod = "box"
     diffMethod = "numeric"
 
@@ -27,27 +29,30 @@ if diffMethod not in ["analytic", "numeric"]:
     raise NotImplementedError(diffMethod + " must be analytic or numeric")
 
 # Initialize the paramaters
-parameters = Parameters({
-    "Problem.EnableGravity": True,
-    "SpatialParams.Porosity": 0.3,
-    "SpatialParams.Permeability": 1e-8,
-    "Vtk.AddVelocity": False,
-    "Assembly.NumericDifference.PriVarMagnitude": 1e5,
-})
+parameters = Parameters(
+    {
+        "Problem.EnableGravity": True,
+        "SpatialParams.Porosity": 0.3,
+        "SpatialParams.Permeability": 1e-8,
+        "Vtk.AddVelocity": False,
+        "Assembly.NumericDifference.PriVarMagnitude": 1e5,
+    }
+)
 
 # Set up the grid and the grid geometry
-gridView = structuredGrid([0,0], [1,1], [10,10])
+gridView = structuredGrid([0, 0], [1, 1], [10, 10])
 gridGeometry = GridGeometry(gridView=gridView, discMethod=discMethod)
 
 # Set up the model
-model = Model(inheritsFrom=['OneP'], gridGeometry=gridGeometry)
+model = Model(inheritsFrom=["OneP"], gridGeometry=gridGeometry)
 
 # Tell Dumux to use a particular local residual type
-model['LocalResidual'] = Property(
-    type='OnePIncompressibleLocalResidual<TypeTag>',
-    includes=['dumux/porousmediumflow/1p/incompressiblelocalresidual.hh']
+model["LocalResidual"] = Property.fromCppType(
+    "OnePIncompressibleLocalResidual<TypeTag>",
+    cppIncludes=["dumux/porousmediumflow/1p/incompressiblelocalresidual.hh"],
 )
 
+
 @OnePSpatialParams(gridGeometry=gridGeometry)
 class SpatialParams:
     dimWorld = gridGeometry.gridView.dimWorld
@@ -57,7 +62,9 @@ class SpatialParams:
     def isLens(self, globalPos):
         eps = 1.5e-7
         for i in range(self.dimWorld):
-            if (globalPos[i] < self.lensLowerLeft[i] + eps) or (globalPos[i] > self.lensUpperRight[i] - eps):
+            if (globalPos[i] < self.lensLowerLeft[i] + eps) or (
+                globalPos[i] > self.lensUpperRight[i] - eps
+            ):
                 return False
         return True
 
@@ -66,20 +73,20 @@ class SpatialParams:
         # permeability can be either given
         # as scalar or tensorial value
         if self.isLens(globalPos):
-            return [[1e-12, 0],
-                    [0, 1e-12]]
+            return [[1e-12, 0], [0, 1e-12]]
         else:
             return 1e-10
 
     def porosityAtPos(self, globalPos):
         return 0.4
 
+
 spatialParams = SpatialParams()
-model['SpatialParams'] = Property(object=spatialParams)
+model["SpatialParams"] = Property.fromInstance(spatialParams)
 
-h20 = Component(name="SimpleH2O")
-onePLiquid = FluidSystem(type="OnePLiquid", component=h20, scalar=model['Scalar'])
-model['FluidSystem'] = Property(object=onePLiquid)
+h20 = Component("SimpleH2O")
+onePLiquid = FluidSystem("OnePLiquid", component=h20, scalar=model["Scalar"])
+model["FluidSystem"] = Property.fromInstance(onePLiquid)
 
 # define the Problem
 @PorousMediumFlowProblem(gridGeometry, spatialParams)
@@ -98,8 +105,8 @@ class Problem:
         return bTypes
 
     def dirichletAtPos(self, globalPos):
-        dp_dy_ = -1.0e+5
-        return  1.0e+5 + dp_dy_*(globalPos[1] - gridGeometry.bBoxMax[1])
+        dp_dy_ = -1.0e5
+        return 1.0e5 + dp_dy_ * (globalPos[1] - gridGeometry.bBoxMax[1])
 
     def sourceAtPos(self, globalPos):
         return 0.0
@@ -119,8 +126,9 @@ class Problem:
     def neumann(self, element, fvGeometry, scvf):
         return 0
 
+
 problem = Problem()
-model['Problem'] = Property(object=problem)
+model["Problem"] = Property.fromInstance(problem)
 
 # initialize the GridVariables and the Assembler
 gridVars = GridVariables(problem=problem, model=model)
@@ -149,5 +157,5 @@ testName = "test_1p_" + discMethod + "_" + diffMethod
 output = VtkOutputModule(gridVariables=gridVars, solutionVector=sol, name=testName)
 velocityoutput = PorousMediumFlowVelocityOutput(gridVariables=gridVars)
 output.addVelocityOutput(velocityoutput)
-output.addVolumeVariable(lambda vv : vv.pressure(), "p")
+output.addVolumeVariable(lambda vv: vv.pressure(), "p")
 output.write(1.0)
diff --git a/test/python/test_explicit_transport_cctpfa.py b/test/python/test_explicit_transport_cctpfa.py
index bf2e26872f..4ad605c3a9 100755
--- a/test/python/test_explicit_transport_cctpfa.py
+++ b/test/python/test_explicit_transport_cctpfa.py
@@ -9,6 +9,7 @@ import numpy as np
 plotting = True
 try:
     import matplotlib.pyplot as plt
+
     plt.ion()
 except ImportError:
     print("Warning: Plots are not generated as matplotlib could not be found.")
@@ -21,7 +22,7 @@ except ImportError:
 dimension = 2
 cells = 20
 
-gridView = structuredGrid([0]*dimension, [1]*dimension, [cells]*dimension)
+gridView = structuredGrid([0] * dimension, [1] * dimension, [cells] * dimension)
 
 gridGeometry = GridGeometry(gridView, discMethod="cctpfa")
 
@@ -61,7 +62,7 @@ problem = Problem()
 # Transport equation #
 ######################
 
-velocity = FieldVector([1]*dimension)
+velocity = FieldVector([1] * dimension)
 upwindWeight = 1.0
 
 
@@ -71,8 +72,9 @@ def advectiveFlux(insideConcentration, outsideConcentration, normal):
     downwindConcentration = outsideConcentration
     if normalVelocity < 0.0:
         upwindConcentration, downwindConcentration = downwindConcentration, upwindConcentration
-    return normalVelocity*(upwindWeight*upwindConcentration
-                           + (1.0-upwindWeight)*downwindConcentration)
+    return normalVelocity * (
+        upwindWeight * upwindConcentration + (1.0 - upwindWeight) * downwindConcentration
+    )
 
 
 ##########################
@@ -86,6 +88,7 @@ solution = np.zeros(gridGeometry.numDofs)
 # Enable plotting #
 ###################
 
+
 @gridFunction(gridView)
 def solutionGridFunction(element, x):
     elementIdx = elementMapper.index(element)
@@ -96,13 +99,15 @@ def plot(time):
     if plotting and dimension == 2:
         fig = plt.figure()
         ax = fig.add_subplot(1, 1, 1)
-        solutionGridFunction.plot(figure=fig, clim=[0, 1+1e-6], gridLines=None)
-        ax.set_title("t = "+"{:0.2f}".format(time))
+        solutionGridFunction.plot(figure=fig, clim=[0, 1 + 1e-6], gridLines=None)
+        ax.set_title("t = " + "{:0.2f}".format(time))
         plt.show()
         plt.pause(1e-3)
-    gridView.writeVTK(problem.name + "-solution-{:0.2f}".format(time).replace(".", ""),
-                      celldata={"solution": solutionGridFunction},
-                      outputType=OutputType.ascii)
+    gridView.writeVTK(
+        problem.name + "-solution-{:0.2f}".format(time).replace(".", ""),
+        celldata={"solution": solutionGridFunction},
+        outputType=OutputType.ascii,
+    )
 
 
 #######################
diff --git a/test/python/test_fvproblem.py b/test/python/test_fvproblem.py
index 26b41d0f75..ebfbd91a5b 100644
--- a/test/python/test_fvproblem.py
+++ b/test/python/test_fvproblem.py
@@ -14,6 +14,7 @@ def PrintProblemTest(problem):
     module = generator.load(includes, typeName, moduleName)
     return module.PrintProblemTest(problem)
 
+
 ############################################################
 # The actual Python test
 ############################################################
@@ -21,10 +22,11 @@ from dune.grid import structuredGrid
 from dumux.discretization import GridGeometry
 from dumux.common import BoundaryTypes, FVProblem
 
-gridView = structuredGrid([0,0,0],[1,1,1],[3,3,3])
+gridView = structuredGrid([0, 0, 0], [1, 1, 1], [3, 3, 3])
 
 gridGeometry = GridGeometry(gridView, discMethod="box")
 
+
 @FVProblem(gridGeometry)
 class Problem:
     numEq = 2
@@ -46,6 +48,7 @@ class Problem:
     def sourceAtPos(self, globalPos):
         return [globalPos[0]]
 
+
 problem = Problem()
 print("Name of the problem: {}".format(problem.name))
 print("-- Number of equations: {}".format(problem.numEq))
-- 
GitLab