summaryrefslogtreecommitdiff
path: root/silx/app/test
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@debian.org>2018-03-04 10:20:27 +0100
committerPicca Frédéric-Emmanuel <picca@debian.org>2018-03-04 10:20:27 +0100
commit270d5ddc31c26b62379e3caa9044dd75ccc71847 (patch)
tree55c5bfc851dfce7172d335cd2405b214323e3caf /silx/app/test
parente19c96eff0c310c06c4f268c8b80cb33bd08996f (diff)
New upstream version 0.7.0+dfsg
Diffstat (limited to 'silx/app/test')
-rw-r--r--silx/app/test/test_convert.py37
-rw-r--r--silx/app/test/test_view.py22
2 files changed, 26 insertions, 33 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
diff --git a/silx/app/test/test_view.py b/silx/app/test/test_view.py
index e55e4f3..aeba0cc 100644
--- a/silx/app/test/test_view.py
+++ b/silx/app/test/test_view.py
@@ -26,29 +26,20 @@
__authors__ = ["V. Valls"]
__license__ = "MIT"
-__date__ = "29/09/2017"
+__date__ = "09/11/2017"
import unittest
import sys
-import os
+from silx.test.utils import test_options
-# TODO: factor this code with silx.gui.test
-with_qt = False
-if sys.platform.startswith('linux') and not os.environ.get('DISPLAY', ''):
- reason = 'test disabled (DISPLAY env. variable not set)'
- view = None
- TestCaseQt = unittest.TestCase
-elif os.environ.get('WITH_QT_TEST', 'True') == 'False':
- reason = "test disabled (env. variable WITH_QT_TEST=False)"
+if not test_options.WITH_QT_TEST:
view = None
TestCaseQt = unittest.TestCase
else:
from silx.gui.test.utils import TestCaseQt
from .. import view
- with_qt = True
- reason = ""
class QApplicationMock(object):
@@ -73,6 +64,9 @@ class ViewerMock(object):
def appendFile(self, filename):
self.appendFileCalls.append(filename)
+ def setAttribute(self, attr, value):
+ pass
+
def resize(self, size):
pass
@@ -80,7 +74,7 @@ class ViewerMock(object):
pass
-@unittest.skipUnless(with_qt, "Qt binding required for TestLauncher")
+@unittest.skipUnless(test_options.WITH_QT_TEST, test_options.WITH_QT_TEST_REASON)
class TestLauncher(unittest.TestCase):
"""Test command line parsing"""
@@ -133,7 +127,7 @@ class TestLauncher(unittest.TestCase):
class TestViewer(TestCaseQt):
"""Test for Viewer class"""
- @unittest.skipUnless(with_qt, reason)
+ @unittest.skipUnless(test_options.WITH_QT_TEST, test_options.WITH_QT_TEST_REASON)
def testConstruct(self):
if view is not None:
widget = view.Viewer()