From 94caee9458645e341c54d23b8a27ff15a0b38c42 Mon Sep 17 00:00:00 2001
From: Michael Kuron <mkuron@icp.uni-stuttgart.de>
Date: Thu, 23 Jan 2020 12:37:00 +0100
Subject: [PATCH] skip more tests based on dependencies

---
 .../01_tutorial_getting_started.ipynb         | 27 +++++++++++--------
 doc/notebooks/demo_wave_equation.ipynb        | 11 +++++---
 pystencils/backends/cbackend.py               |  2 +-
 pystencils_tests/test_loop_cutting.py         |  4 +++
 pystencils_tests/test_plot.py                 |  4 +++
 pystencils_tests/test_staggered_kernel.py     |  3 +++
 6 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/doc/notebooks/01_tutorial_getting_started.ipynb b/doc/notebooks/01_tutorial_getting_started.ipynb
index 97ff73da1..8ae0745ee 100644
--- a/doc/notebooks/01_tutorial_getting_started.ipynb
+++ b/doc/notebooks/01_tutorial_getting_started.ipynb
@@ -932,14 +932,18 @@
     }
    ],
    "source": [
-    "import requests\n",
-    "import imageio\n",
-    "from io import BytesIO\n",
+    "try:\n",
+    "    import requests\n",
+    "    import imageio\n",
+    "    from io import BytesIO\n",
     "\n",
-    "response = requests.get(\"https://www.python.org/static/img/python-logo.png\")\n",
-    "img = imageio.imread(BytesIO(response.content)).astype(np.double)\n",
-    "img /= img.max()\n",
-    "plt.imshow(img);"
+    "    response = requests.get(\"https://www.python.org/static/img/python-logo.png\")\n",
+    "    img = imageio.imread(BytesIO(response.content)).astype(np.double)\n",
+    "    img /= img.max()\n",
+    "    plt.imshow(img);\n",
+    "except ImportError:\n",
+    "    print(\"No requests installed\")\n",
+    "    img = None"
    ]
   },
   {
@@ -961,10 +965,11 @@
     }
    ],
    "source": [
-    "filtered_image = np.zeros_like(img[..., 0])\n",
-    "# here we call the compiled stencil function\n",
-    "compiled_kernel(img=img, dst=filtered_image, w_2=0.5)\n",
-    "plt.imshow(filtered_image, cmap='gray');"
+    "if img:\n",
+    "    filtered_image = np.zeros_like(img[..., 0])\n",
+    "    # here we call the compiled stencil function\n",
+    "    compiled_kernel(img=img, dst=filtered_image, w_2=0.5)\n",
+    "    plt.imshow(filtered_image, cmap='gray');"
    ]
   },
   {
diff --git a/doc/notebooks/demo_wave_equation.ipynb b/doc/notebooks/demo_wave_equation.ipynb
index a4d5a9ff7..007e9a7b5 100644
--- a/doc/notebooks/demo_wave_equation.ipynb
+++ b/doc/notebooks/demo_wave_equation.ipynb
@@ -8,7 +8,9 @@
    },
    "outputs": [],
    "source": [
-    "from pystencils.session import *"
+    "from pystencils.session import *\n",
+    "\n",
+    "import shutil"
    ]
   },
   {
@@ -397,8 +399,11 @@
     }
    ],
    "source": [
-    "ani = plt.surface_plot_animation(run, zlim=(-1, 1))\n",
-    "ps.jupyter.display_as_html_video(ani)"
+    "if shutil.which(\"ffmpeg\") is not None:\n",
+    "    ani = plt.surface_plot_animation(run, zlim=(-1, 1))\n",
+    "    ps.jupyter.display_as_html_video(ani)\n",
+    "else:\n",
+    "    print(\"No ffmpeg installed\")"
    ]
   },
   {
diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py
index 1c7c722cb..c00d6028b 100644
--- a/pystencils/backends/cbackend.py
+++ b/pystencils/backends/cbackend.py
@@ -389,7 +389,7 @@ class CustomSympyPrinter(CCodePrinter):
         elif isinstance(expr, sp.Abs):
             return "abs({})".format(self._print(expr.args[0]))
         elif isinstance(expr, sp.Mod):
-            if expr.is_integer:
+            if expr.args[0].is_integer and expr.args[1].is_integer:
                 return "({} % {})".format(self._print(expr.args[0]), self._print(expr.args[1]))
             else:
                 return "fmod({}, {})".format(self._print(expr.args[0]), self._print(expr.args[1]))
diff --git a/pystencils_tests/test_loop_cutting.py b/pystencils_tests/test_loop_cutting.py
index cd89f37f6..0291074b8 100644
--- a/pystencils_tests/test_loop_cutting.py
+++ b/pystencils_tests/test_loop_cutting.py
@@ -1,6 +1,8 @@
 import numpy as np
 import sympy as sp
 
+import pytest
+
 import pystencils as ps
 import pystencils.astnodes as ast
 from pystencils.field import Field, FieldType
@@ -57,6 +59,7 @@ def test_staggered_iteration():
                                sum(f[o] for o in offsets_in_plane(d, -1, dim)))
         assignments = [ps.Assignment(s.staggered_access(d), expressions[i]) for i, d in enumerate(s.staggered_stencil)]
         func_optimized = create_staggered_kernel(assignments).compile()
+        pytest.importorskip('islpy')
         assert not func_optimized.ast.atoms(Conditional), "Loop cutting optimization did not work"
 
         func(f=f_arr, s=s_arr_ref)
@@ -99,6 +102,7 @@ def test_staggered_iteration_manual():
     move_constants_before_loop(kernel_ast.body)
     cleanup_blocks(kernel_ast.body)
 
+    pytest.importorskip('islpy')
     assert not kernel_ast.atoms(Conditional), "Loop cutting optimization did not work"
 
     func_optimized = make_python_function(kernel_ast)
diff --git a/pystencils_tests/test_plot.py b/pystencils_tests/test_plot.py
index 6234334bb..4c9207216 100644
--- a/pystencils_tests/test_plot.py
+++ b/pystencils_tests/test_plot.py
@@ -1,5 +1,8 @@
 import os
 from tempfile import TemporaryDirectory
+import shutil
+
+import pytest
 
 import numpy as np
 
@@ -20,6 +23,7 @@ def example_vector_field(t=0, shape=(40, 40)):
     return result
 
 
+@pytest.mark.skipif(shutil.which('ffmpeg') is None, reason="ffmpeg not available")
 def test_animation():
     t = 0
 
diff --git a/pystencils_tests/test_staggered_kernel.py b/pystencils_tests/test_staggered_kernel.py
index 310220d21..c4f491393 100644
--- a/pystencils_tests/test_staggered_kernel.py
+++ b/pystencils_tests/test_staggered_kernel.py
@@ -1,6 +1,8 @@
 import numpy as np
 import sympy as sp
 
+import pytest
+
 import pystencils as ps
 
 
@@ -88,6 +90,7 @@ def test_staggered_subexpressions():
 
 
 def test_staggered_loop_cutting():
+    pytest.importorskip('islpy')
     dh = ps.create_data_handling((4, 4), periodicity=True, default_target='cpu')
     j = dh.add_array('j', values_per_cell=4, field_type=ps.FieldType.STAGGERED)
     assignments = [ps.Assignment(j.staggered_access("SW"), 1)]
-- 
GitLab