Improvements of tests to account for potentially missing modules
@@ -42,10 +42,13 @@ class TestDataProviders(QiskitAquaTestCase):
[8.44268222e-05, 1.00000000e+00]])
covariance = np.array([[269.60118129, 25.42252332],
[ 25.42252332, 7.86304499]])
- self.get_similarity_matrix()
self.get_covariance()
- numpy.testing.assert_array_almost_equal(self.rho, similarity, decimal = 3)
numpy.testing.assert_array_almost_equal(self.cov, covariance, decimal = 3)
+ import fastdtw # This is to trigger an exception skipping the rest of the test, in case the module is not available
+ self.get_similarity_matrix()
+ numpy.testing.assert_array_almost_equal(self.rho, similarity, decimal = 3)
+ except ImportError:
+ print("One part of a test of WikipediaDataProvider skipped due the lack of fastdtw/quandl.")
except QiskitFinanceError:
print("Test of WikipediaDataProvider skipped due to the per-day usage limits.")
# The trouble for automating testing is that after 50 tries from one IP address within a day
@@ -63,8 +66,13 @@ class TestDataProviders(QiskitAquaTestCase):
stockmarket = StockMarket.NASDAQ.value,
start = datetime.datetime(2016,1,1),
end = datetime.datetime(2016,1,2))
- with self.assertRaises(QiskitFinanceError):
+ try:
nasdaq.run()
+ self.fail("Test of DataOnDemandProvider should have failed due to the lack of a token.")
+ except ImportError:
+ print("Test of DataOnDemandProvider skipped due the lack of quandl.")
+ except QiskitFinanceError:
+ print("Test of DataOnDemandProvider skipped due to the lack of a token.")
# will throw QiskitFinanceError, because there is no valid token; otherwise, we could continue as:
"""
similarity = np.array([[1.00000000e+00, 8.44268222e-05],
@@ -84,5 +92,10 @@ class TestDataProviders(QiskitAquaTestCase):
stockmarket = StockMarket.LONDON.value,
start = datetime.datetime(2019,1,1),
end = datetime.datetime(2019,1,30))
- with self.assertRaises(QiskitFinanceError):
+ try:
lse.run()
+ self.fail("Test of DataOnDemandProvider should have failed due to the lack of a token.")
+ except ImportError:
+ print("Test of DataOnDemandProvider skipped due the lack of quandl.")
+ except QiskitFinanceError:
+ print("Test of DataOnDemandProvider skipped due to the lack of a token.")
