Repository: obspy/obspy

Issue:
Test fails in UTCDateTime.matplotlib_date
Current master, see https://tests.obspy.org/111684/#3 and #2689 

e.g.
```
File "/home/runner/work/obspy/obspy/obspy/core/trace.py", line 2536, in obspy.core.trace.Trace.times
Failed example:
tr.times("matplotlib")
Expected:
array([ 733643.01392361, 733643.01392373, 733643.01392384, ...,
733643.01427049, 733643.0142706 , 733643.01427072])
Got:
array([ 14480.01392361, 14480.01392373, 14480.01392384, ...,
14480.01427049, 14480.0142706 , 14480.01427072])
```



Discussion:
Probably the epoch change https://matplotlib.org/users/whats_new.html#dates-use-a-modern-epoch
Ah, thanks for the link, so basically everything's fine and we just have to use `set_epoch()` in our test suite.
Actually with all the different ways our tests can be executed, it might be a bit tricky to swap to the epoch that test results expect in all cases for doctests (unittests should be trivial, can just use `set_poch()` inside the test method)..
 - via `$ obspy-runtests`: can simply use `set_epoch()` inside `scripts/runtests.py`
 - via `$ pytest ...`: could maybe check for [`PYTEST_CURRENT_TEST`](https://docs.pytest.org/en/4.6.1/example/simple.html#pytest-current-test-environment-variable) inside `UTCDateTime.matplotlib_date()`  (although seems a bit convoluted)
 - via `$ python some_of_our_files.py` -- maybe no chance

Resolving patch:
diff --git a/obspy/core/trace.py b/obspy/core/trace.py
--- a/obspy/core/trace.py
+++ b/obspy/core/trace.py
@@ -2526,9 +2526,9 @@ def times(self, type="relative", reftime=None):
         array([  1.25107320e+09,   1.25107320e+09,   1.25107320e+09, ...,
                  1.25107323e+09,   1.25107323e+09,   1.25107323e+09])
 
-        >>> tr.times("matplotlib")
-        array([ 733643.01392361,  733643.01392373,  733643.01392384, ...,
-                733643.01427049,  733643.0142706 ,  733643.01427072])
+        >>> tr.times("matplotlib")  # doctest: +SKIP
+        array([ 14480.01392361,  14480.01392373,  14480.01392384, ...,
+                14480.01427049,  14480.0142706 ,  14480.01427072])
 
         :type type: str
         :param type: Determines type of returned time array, see above for
diff --git a/obspy/core/utcdatetime.py b/obspy/core/utcdatetime.py
--- a/obspy/core/utcdatetime.py
+++ b/obspy/core/utcdatetime.py
@@ -1712,8 +1712,8 @@ def matplotlib_date(self):
         :meth:`obspy.core.stream.Stream.plot()`.
 
         >>> t = UTCDateTime("2009-08-24T00:20:07.700000Z")
-        >>> t.matplotlib_date
-        733643.0139780092
+        >>> t.matplotlib_date  # doctest: +SKIP
+        14480.01397800926
 
         :rtype: float
         """
diff --git a/obspy/imaging/maps.py b/obspy/imaging/maps.py
--- a/obspy/imaging/maps.py
+++ b/obspy/imaging/maps.py
@@ -30,8 +30,13 @@
 
 
 if BASEMAP_VERSION:
-    from mpl_toolkits.basemap import Basemap
-    HAS_BASEMAP = True
+    try:
+        from mpl_toolkits.basemap import Basemap
+    except ImportError as ex:
+        warnings.warn("Basemap installation not working: %s" % ex)
+        HAS_BASEMAP = False
+    else:
+        HAS_BASEMAP = True
     if BASEMAP_VERSION < [1, 0, 4]:
         warnings.warn("All basemap version < 1.0.4 contain a serious bug "
                       "when rendering countries and continents. ObsPy will "


Test patch:
diff --git a/obspy/core/tests/test_network.py b/obspy/core/tests/test_network.py
--- a/obspy/core/tests/test_network.py
+++ b/obspy/core/tests/test_network.py
@@ -29,6 +29,7 @@
 from obspy.core.util.testing import ImageComparison
 from obspy.core.inventory import (Channel, Inventory, Network, Response,
                                   Station)
+from obspy.imaging.maps import HAS_BASEMAP
 
 
 class NetworkTestCase(unittest.TestCase):
@@ -319,7 +320,7 @@ def test_empty_network_code(self):
         self.assertEqual(inv, inv2)
 
 
-@unittest.skipIf(not BASEMAP_VERSION, 'basemap not installed')
+@unittest.skipIf(not HAS_BASEMAP, 'no or invalid basemap installation')
 @unittest.skipIf(
     BASEMAP_VERSION >= [1, 1, 0] and MATPLOTLIB_VERSION == [3, 0, 1],
     'matplotlib 3.0.1 is not compatible with basemap')
diff --git a/obspy/core/tests/test_trace.py b/obspy/core/tests/test_trace.py
--- a/obspy/core/tests/test_trace.py
+++ b/obspy/core/tests/test_trace.py
@@ -1406,6 +1406,8 @@ def test_times(self):
         Test if the correct times array is returned for normal traces and
         traces with gaps.
         """
+        from distutils.version import LooseVersion
+        from matplotlib import __version__
         tr = Trace(data=np.ones(100))
         tr.stats.sampling_rate = 20
         delta = tr.stats.delta
@@ -1442,9 +1444,13 @@ def test_times(self):
         np.testing.assert_allclose(got[:5], expected, rtol=1e-17)
         got = tr.times("matplotlib")
         expected = np.array([
-            730120.00000000000000000000, 730120.00000057870056480169,
-            730120.00000115740112960339, 730120.00000173610169440508,
-            730120.00000231480225920677])
+                10957.000000000000, 10957.000000578704, 10957.000001157407,
+                10957.000001736111, 10957.000002314815])
+        if LooseVersion(__version__) < LooseVersion('3.3'):
+            expected = np.array([
+                730120.00000000000000000000, 730120.00000057870056480169,
+                730120.00000115740112960339, 730120.00000173610169440508,
+                730120.00000231480225920677])
         np.testing.assert_allclose(got[:5], expected, rtol=1e-17)
 
     def test_modulo_operation(self):
diff --git a/obspy/core/tests/test_utcdatetime.py b/obspy/core/tests/test_utcdatetime.py
--- a/obspy/core/tests/test_utcdatetime.py
+++ b/obspy/core/tests/test_utcdatetime.py
@@ -1084,11 +1084,18 @@ def test_matplotlib_date(self):
         Test convenience method and property for conversion to matplotlib
         datetime float numbers.
         """
-        for t_, expected in zip(
+        from distutils.version import LooseVersion
+        from matplotlib import __version__
+
+        for t_, expected_old, expected in zip(
                 ("1986-05-02T13:44:12.567890Z", "2009-08-24T00:20:07.700000Z",
                  "2026-11-27T03:12:45.4"),
-                (725128.5723676839, 733643.0139780092, 739947.1338587963)):
+                (725128.5723676839, 733643.0139780092, 739947.1338587963),
+                (5965.57236768, 14480.013978, 20784.1338588),
+                ):
             t = UTCDateTime(t_)
+            if LooseVersion(__version__) < LooseVersion('3.3'):
+                expected = expected_old
             np.testing.assert_almost_equal(
                 t.matplotlib_date, expected, decimal=8)