summaryrefslogtreecommitdiff
path: root/silx/io/test
diff options
context:
space:
mode:
Diffstat (limited to 'silx/io/test')
-rw-r--r--silx/io/test/test_specfile.py13
-rw-r--r--silx/io/test/test_spech5.py11
-rw-r--r--silx/io/test/test_spectoh5.py4
-rw-r--r--silx/io/test/test_utils.py20
4 files changed, 35 insertions, 13 deletions
diff --git a/silx/io/test/test_specfile.py b/silx/io/test/test_specfile.py
index 55850f1..79d5544 100644
--- a/silx/io/test/test_specfile.py
+++ b/silx/io/test/test_specfile.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016-2017 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -224,14 +224,21 @@ class TestSpecFile(unittest.TestCase):
with self.assertRaises(specfile.SfErrScanNotFound):
self.sf.index(99)
+ def assertRaisesRegex(self, *args, **kwargs):
+ # Python 2 compatibility
+ if sys.version_info.major >= 3:
+ return super(TestSpecFile, self).assertRaisesRegex(*args, **kwargs)
+ else:
+ return self.assertRaisesRegexp(*args, **kwargs)
+
def test_getitem(self):
self.assertIsInstance(self.sf[2], Scan)
self.assertIsInstance(self.sf["1.2"], Scan)
# int out of range
- with self.assertRaisesRegexp(IndexError, 'Scan index must be in ran'):
+ with self.assertRaisesRegex(IndexError, 'Scan index must be in ran'):
self.sf[107]
# float indexing not allowed
- with self.assertRaisesRegexp(TypeError, 'The scan identification k'):
+ with self.assertRaisesRegex(TypeError, 'The scan identification k'):
self.sf[1.2]
# non existant scan with "N.M" indexing
with self.assertRaises(KeyError):
diff --git a/silx/io/test/test_spech5.py b/silx/io/test/test_spech5.py
index 7c8ed5d..0263c3c 100644
--- a/silx/io/test/test_spech5.py
+++ b/silx/io/test/test_spech5.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -272,6 +272,13 @@ class TestSpecH5(unittest.TestCase):
self.assertEqual(self.sfh5["25.1/start_time"],
u"2015-03-14T03:53:50")
+ def assertRaisesRegex(self, *args, **kwargs):
+ # Python 2 compatibility
+ if sys.version_info.major >= 3:
+ return super(TestSpecH5, self).assertRaisesRegex(*args, **kwargs)
+ else:
+ return self.assertRaisesRegexp(*args, **kwargs)
+
def testDatasetInstanceAttr(self):
"""The SpecH5Dataset objects must implement some dummy attributes
to improve compatibility with widgets dealing with h5py datasets."""
@@ -279,7 +286,7 @@ class TestSpecH5(unittest.TestCase):
self.assertIsNone(self.sfh5["1.1"]["measurement"]["MRTSlit UP"].chunks)
# error message must be explicit
- with self.assertRaisesRegexp(
+ with self.assertRaisesRegex(
AttributeError,
"SpecH5Dataset has no attribute tOTo"):
dummy = self.sfh5["/1.1/start_time"].tOTo
diff --git a/silx/io/test/test_spectoh5.py b/silx/io/test/test_spectoh5.py
index 2b79704..44b59e0 100644
--- a/silx/io/test/test_spectoh5.py
+++ b/silx/io/test/test_spectoh5.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -132,7 +132,7 @@ class TestConvertSpecHDF5(unittest.TestCase):
def testTitle(self):
"""Test the value of a dataset"""
- title12 = self.h5f["/1.2/title"].value
+ title12 = self.h5f["/1.2/title"][()]
self.assertEqual(title12,
u"aaaaaa")
diff --git a/silx/io/test/test_utils.py b/silx/io/test/test_utils.py
index 5a4c629..56f89fc 100644
--- a/silx/io/test/test_utils.py
+++ b/silx/io/test/test_utils.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -30,6 +30,7 @@ import re
import shutil
import tempfile
import unittest
+import sys
from .. import utils
import silx.io.url
@@ -102,6 +103,13 @@ class TestSave(unittest.TestCase):
os.unlink(self.npy_fname)
shutil.rmtree(self.tempdir)
+ def assertRegex(self, *args, **kwargs):
+ # Python 2 compatibility
+ if sys.version_info.major >= 3:
+ return super(TestSave, self).assertRegex(*args, **kwargs)
+ else:
+ return self.assertRegexpMatches(*args, **kwargs)
+
def test_save_csv(self):
utils.save1D(self.csv_fname, self.x, self.y,
xlabel=self.xlab, ylabels=self.ylabs,
@@ -112,7 +120,7 @@ class TestSave(unittest.TestCase):
actual_csv = csvf.read()
csvf.close()
- self.assertRegexpMatches(actual_csv, expected_csv)
+ self.assertRegex(actual_csv, expected_csv)
def test_save_npy(self):
"""npy file is saved with numpy.save after building a numpy array
@@ -138,7 +146,7 @@ class TestSave(unittest.TestCase):
actual_spec = specf.read()
specf.close()
- self.assertRegexpMatches(actual_spec, expected_spec1)
+ self.assertRegex(actual_spec, expected_spec1)
def test_savespec_file_handle(self):
"""Save SpecFile using savespec(), passing a file handle"""
@@ -158,7 +166,7 @@ class TestSave(unittest.TestCase):
actual_spec = specf.read()
specf.close()
- self.assertRegexpMatches(actual_spec, expected_spec2)
+ self.assertRegex(actual_spec, expected_spec2)
def test_save_spec(self):
"""Save SpecFile using save()"""
@@ -168,7 +176,7 @@ class TestSave(unittest.TestCase):
specf = open(self.spec_fname)
actual_spec = specf.read()
specf.close()
- self.assertRegexpMatches(actual_spec, expected_spec2)
+ self.assertRegex(actual_spec, expected_spec2)
def test_save_csv_no_labels(self):
"""Save csv using save(), with autoheader=True but
@@ -189,7 +197,7 @@ class TestSave(unittest.TestCase):
csvf = open(self.csv_fname)
actual_csv = csvf.read()
csvf.close()
- self.assertRegexpMatches(actual_csv, expected_csv2)
+ self.assertRegex(actual_csv, expected_csv2)
def assert_match_any_string_in_list(test, pattern, list_of_strings):