Bladeren bron

test: now tests should work also without Pandas

Mikael Koli 4 jaren geleden
bovenliggende
commit
2b41416bcd

+ 0 - 5
redmail/test/email/test_attachments.py

@@ -1,15 +1,10 @@
 
 from redmail import EmailSender
 
-import re
 import base64
 
 from pathlib import Path
-from io import BytesIO
 import pytest
-import pandas as pd
-
-import numpy as np
 
 from resources import get_mpl_fig, get_pil_image
 from convert import remove_extra_lines

+ 0 - 1
redmail/test/email/test_body.py

@@ -1,7 +1,6 @@
 from redmail import EmailSender
 
 import pytest
-import pandas as pd
 
 from convert import remove_extra_lines
 from getpass import getpass, getuser

+ 12 - 11
redmail/test/email/test_inline_media.py

@@ -6,9 +6,9 @@ import re
 from pathlib import Path
 from io import BytesIO
 import pytest
-import pandas as pd
 
-import numpy as np
+# Importing Pandas from utils (is None if missing package)
+from redmail.email.utils import pd
 
 from resources import get_mpl_fig, get_pil_image
 from convert import remove_extra_lines
@@ -108,23 +108,23 @@ def test_with_image_obj(get_image_obj):
 
 
 @pytest.mark.parametrize(
-    "df,", [
+    "get_df,", [
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                 columns=pd.Index(["first", "second", "third"]),
             ), 
             id="Simple dataframe"
         ),
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [[1], [2], [3]],
                 columns=pd.Index(["first"]),
             ), 
             id="Single column datafram"
         ),
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                 columns=pd.Index(["first", "second", "third"]),
                 index=pd.Index(["a", "b", "c"], name="category")
@@ -132,7 +132,7 @@ def test_with_image_obj(get_image_obj):
             id="Simple dataframe with index"
         ),
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [[1, 2, 3, "a"], [4, 5, 6, "b"], [7, 8, 9, "c"], [10, 11, 12, "d"]],
                 columns=pd.MultiIndex.from_tuples([("parent a", "child a"), ("parent a", "child b"), ("parent b", "child a"), ("parent c", "child a")], names=["lvl 1", "lvl 2"]),
                 index=pd.MultiIndex.from_tuples([("row a", "sub a"), ("row a", "sub b"), ("row b", "sub a"), ("row c", "sub a")], names=["cat 1", "cat 2"]),
@@ -140,7 +140,7 @@ def test_with_image_obj(get_image_obj):
             id="Complex dataframe"
         ),
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [[1, 2], [4, 5]],
                 columns=pd.MultiIndex.from_tuples([("col a", "child b", "subchild a"), ("col a", "child b", "subchild a")]),
                 index=pd.MultiIndex.from_tuples([("row a", "child b", "subchild a"), ("row a", "child b", "subchild a")]),
@@ -148,7 +148,7 @@ def test_with_image_obj(get_image_obj):
             id="Multiindex end with spanned"
         ),
         pytest.param(
-            pd.DataFrame(
+            lambda: pd.DataFrame(
                 [],
                 columns=pd.Index(["first", "second", "third"]),
             ), 
@@ -156,8 +156,9 @@ def test_with_image_obj(get_image_obj):
         ),
     ]
 )
-def test_with_html_table_no_error(df, tmpdir):
-
+def test_with_html_table_no_error(get_df, tmpdir):
+    pytest.importorskip("pandas")
+    df = get_df()
     sender = EmailSender(host=None, port=1234)
     msg = sender.get_message(
         sender="me@gmail.com",

+ 0 - 1
redmail/test/email/test_template.py

@@ -1,7 +1,6 @@
 from redmail import EmailSender
 
 import pytest
-import pandas as pd
 
 from convert import remove_email_extra
 from getpass import getpass, getuser

+ 1 - 4
redmail/test/helpers/resources.py

@@ -1,5 +1,4 @@
 
-import numpy as np
 from io import BytesIO
 
 import pytest
@@ -8,10 +7,8 @@ def get_mpl_fig():
     pytest.importorskip("matplotlib")
     import matplotlib.pyplot as plt
     # Data for plotting
-    t = np.arange(0.0, 2.0, 0.01)
-    s = 1 + np.sin(2 * np.pi * t)
     fig, ax = plt.subplots()
-    ax.plot(t, s)
+    ax.plot([1, 2, 3])
 
     buf = BytesIO()
     fig.savefig(buf, format='png')