File python-django-tables2-tests-noxls.patch of Package python-django-tables2
diff -ur django-tables2-2.7.0.orig/tests/test_export.py django-tables2-2.7.0/tests/test_export.py
--- django-tables2-2.7.0.orig/tests/test_export.py 2025-01-20 22:02:07.563751814 +0100
+++ django-tables2-2.7.0/tests/test_export.py 2025-01-20 22:06:11.512640850 +0100
@@ -24,6 +24,10 @@
except ImproperlyConfigured:
TableExport = None
+try:
+ import xlwt
+except ImportError:
+ xlwt = None
NAMES = [("Yildiz", "van der Kuil"), ("Lindi", "Hakvoort"), ("Gerardo", "Castelein")]
NAMES_LIST_OF_DICTS = [
@@ -255,6 +259,7 @@
Occupation.objects.create(name="Timmerman", boolean=True, region=vlaanderen)
Occupation.objects.create(name="Ecoloog", boolean=False, region=vlaanderen)
+ @skipIf(xlwt is None, "tablib[xls] (xlwt) is required to run this export test")
def test_should_work_with_foreign_keys(self):
response = OccupationView.as_view()(build_request("/?_export=xls"))
data = response.content
@@ -263,6 +268,7 @@
self.assertTrue(data.find(b"Ecoloog"))
self.assertTrue(data.find(b"Timmerman"))
+ @skipIf(xlwt is None, "tablib[xls] (xlwt) is required to run this export test")
def test_datetime_xls(self):
"""Verify datatime objects can be exported to xls."""
@@ -375,8 +381,9 @@
self.assertEqual(response.getvalue().decode("utf8"), expected_csv)
# smoke tests, hard to test this binary format for string containment
- response = OccupationView.as_view()(build_request("/?_export=xls"))
- self.assertGreater(len(response.content), len(expected_csv))
+ if xlwt is not None:
+ response = OccupationView.as_view()(build_request("/?_export=xls"))
+ self.assertGreater(len(response.content), len(expected_csv))
response = OccupationView.as_view()(build_request("/?_export=xlsx"))
self.assertGreater(len(response.content), len(expected_csv))
@@ -391,6 +398,7 @@
response = exporter.response()
self.assertEqual(response.getvalue().decode("utf8"), unicode_header + "\r\n")
- exporter = TableExport("xls", Table([]))
- # this would fail if the header contains unicode and string converstion is attempted.
- exporter.export()
+ if xlwt is not None:
+ exporter = TableExport("xls", Table([]))
+ # this would fail if the header contains unicode and string converstion is attempted.
+ exporter.export()