diff options
Diffstat (limited to 'silx/app/test/test_convert.py')
-rw-r--r-- | silx/app/test/test_convert.py | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/silx/app/test/test_convert.py b/silx/app/test/test_convert.py index 3215460..97be3fd 100644 --- a/silx/app/test/test_convert.py +++ b/silx/app/test/test_convert.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2016-2017 European Synchrotron Radiation Facility +# Copyright (c) 2016-2018 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 @@ -26,7 +26,7 @@ __authors__ = ["P. Knobel"] __license__ = "MIT" -__date__ = "12/09/2017" +__date__ = "17/01/2018" import os @@ -43,7 +43,7 @@ except ImportError: import silx from .. import convert -from silx.test import utils +from silx.utils import testutils @@ -103,13 +103,12 @@ class TestConvertCommand(unittest.TestCase): result = e.args[0] self.assertEqual(result, 0) - @unittest.skipUnless(h5py is None, - "h5py is installed, this test is specific to h5py missing") - @utils.test_logging(convert._logger.name, error=1) + @testutils.test_logging(convert._logger.name, error=1) def testH5pyNotInstalled(self): - result = convert.main(["convert", "foo.spec", "bar.edf"]) - # we explicitly return -1 if h5py is not imported - self.assertNotEqual(result, 0) + with testutils.EnsureImportError("h5py"): + result = convert.main(["convert", "foo.spec", "bar.edf"]) + # we explicitly return -1 if h5py is not imported + self.assertNotEqual(result, 0) @unittest.skipIf(h5py is None, "h5py is required to test convert") def testWrongOption(self): @@ -122,7 +121,7 @@ class TestConvertCommand(unittest.TestCase): self.assertNotEqual(result, 0) @unittest.skipIf(h5py is None, "h5py is required to test convert") - @utils.test_logging(convert._logger.name, error=3) + @testutils.test_logging(convert._logger.name, error=3) # one error log per missing file + one "Aborted" error log def testWrongFiles(self): result = convert.main(["convert", "foo.spec", "bar.edf"]) @@ -136,15 +135,16 @@ class TestConvertCommand(unittest.TestCase): # write a temporary SPEC file specname = os.path.join(tempdir, "input.dat") with io.open(specname, "wb") as fd: - if sys.version < '3.0': + if sys.version_info < (3, ): fd.write(sftext) else: fd.write(bytes(sftext, 'ascii')) # convert it h5name = os.path.join(tempdir, "output.h5") + assert not os.path.isfile(h5name) command_list = ["convert", "-m", "w", - "--no-root-group", specname, "-o", h5name] + specname, "-o", h5name] result = convert.main(command_list) self.assertEqual(result, 0) @@ -152,17 +152,16 @@ class TestConvertCommand(unittest.TestCase): with h5py.File(h5name, "r") as h5f: title12 = h5f["/1.2/title"][()] - if sys.version > '3.0': - title12 = title12.decode() + if sys.version_info < (3, ): + title12 = title12.encode("utf-8") self.assertEqual(title12, - "1 aaaaaa") + "aaaaaa") creator = h5f.attrs.get("creator") self.assertIsNotNone(creator, "No creator attribute in NXroot group") - creator = creator.decode() # make sure we can compare creator with native string - self.assertTrue(creator.startswith("silx %s" % silx.version)) - command = " ".join(command_list) - self.assertTrue(creator.endswith(command)) + if sys.version_info < (3, ): + creator = creator.encode("utf-8") + self.assertIn("silx convert (v%s)" % silx.version, creator) # delete input file gc.collect() # necessary to free spec file on Windows |