From 378cab43504ce3f21752dece3bb34308f043b681 Mon Sep 17 00:00:00 2001 From: jevans Date: Sat, 18 Oct 2014 21:41:44 -0400 Subject: [PATCH] replaced windows temp file skip messages with a constant, closes #276 --- glymur/test/fixtures.py | 3 +++ glymur/test/test_config.py | 10 +++++++--- glymur/test/test_jp2box.py | 20 +++++++++----------- glymur/test/test_jp2box_xml.py | 5 +++-- glymur/test/test_jp2k.py | 26 +++++++++++++------------- glymur/test/test_opj_suite_write.py | 8 ++++---- 6 files changed, 39 insertions(+), 33 deletions(-) diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 838756a..4b3972c 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -26,6 +26,9 @@ elif re.match('1.[0-6]', six.__version__) is not None: msg = "Cannot run test with version {0} of python-six" WARNING_INFRASTRUCTURE_MSG = msg.format(six.__version__) +# Cannot reopen a named temporary file in windows. +WINDOWS_TMP_FILE_MSG = "cannot use NamedTemporaryFile like this in windows" + class MetadataBase(unittest.TestCase): """ Base class for testing metadata. diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index f908272..477e2e3 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -25,7 +25,11 @@ else: import glymur from glymur import Jp2k -from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG +from .fixtures import ( + WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, + WINDOWS_TMP_FILE_MSG +) + @unittest.skipIf(sys.hexversion < 0x03020000, "TemporaryDirectory introduced in 3.2.") @@ -71,7 +75,7 @@ class TestSuite(unittest.TestCase): Jp2k(self.jp2file) @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) - @unittest.skipIf(os.name == "nt", 'named temporary file issue on windows') + @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) def test_xdg_env_config_file_is_bad(self): """A non-existant library location should be rejected.""" with tempfile.TemporaryDirectory() as tdir: @@ -122,7 +126,7 @@ class TestConfig(unittest.TestCase): with self.assertRaises(glymur.jp2k.LibraryNotFoundError): glymur.Jp2k(self.jp2file).read_bands() - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) def test_write_without_library(self): """Don't have openjpeg libraries? Must error out. """ diff --git a/glymur/test/test_jp2box.py b/glymur/test/test_jp2box.py index 061ad23..7246349 100644 --- a/glymur/test/test_jp2box.py +++ b/glymur/test/test_jp2box.py @@ -37,7 +37,7 @@ from glymur.core import RED, GREEN, BLUE, GREY, WHOLE_IMAGE from .fixtures import ( WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, - MetadataBase + WINDOWS_TMP_FILE_MSG, MetadataBase ) try: @@ -54,7 +54,7 @@ def load_tests(loader, tests, ignore): tests.addTests(doctest.DocTestSuite('glymur.jp2box')) return tests -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestDataEntryURL(unittest.TestCase): """Test suite for DataEntryURL boxes.""" def setUp(self): @@ -122,7 +122,7 @@ class TestDataEntryURL(unittest.TestCase): @unittest.skipIf(re.match(r'''(1|2.0.0)''', glymur.version.openjpeg_version) is not None, "Not supported until 2.1") -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestChannelDefinition(unittest.TestCase): """Test suite for channel definition boxes.""" @@ -434,8 +434,7 @@ class TestColourSpecificationBox(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(os.name == "nt", - "Problems using NamedTemporaryFile on windows.") + @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) def test_colr_with_out_enum_cspace(self): """must supply an enumerated colorspace when writing""" j2k = Jp2k(self.j2kfile) @@ -446,7 +445,7 @@ class TestColourSpecificationBox(unittest.TestCase): with self.assertRaises(IOError): j2k.wrap(tfile.name, boxes=boxes) - @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") + @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) def test_missing_colr_box(self): """jp2h must have a colr box""" j2k = Jp2k(self.j2kfile) @@ -456,7 +455,7 @@ class TestColourSpecificationBox(unittest.TestCase): with self.assertRaises(IOError): j2k.wrap(tfile.name, boxes=boxes) - @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") + @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) def test_bad_approx_jp2_field(self): """JP2 has requirements for approx field""" j2k = Jp2k(self.j2kfile) @@ -517,8 +516,7 @@ class TestColourSpecificationBox(unittest.TestCase): colr.write(tfile) -@unittest.skipIf(os.name == "nt", - "Problems using NamedTemporaryFile on windows.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestPaletteBox(unittest.TestCase): """Test suite for pclr box instantiation.""" @@ -560,7 +558,7 @@ class TestPaletteBox(unittest.TestCase): pclr.write(tfile) -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestAppend(unittest.TestCase): """Tests for append method.""" @@ -653,7 +651,7 @@ class TestAppend(unittest.TestCase): jp2.append(uuidbox) -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG) class TestWrap(unittest.TestCase): """Tests for wrap method.""" diff --git a/glymur/test/test_jp2box_xml.py b/glymur/test/test_jp2box_xml.py index eeb1fa8..45d02f1 100644 --- a/glymur/test/test_jp2box_xml.py +++ b/glymur/test/test_jp2box_xml.py @@ -41,8 +41,9 @@ from glymur.jp2box import JPEG2000SignatureBox from .fixtures import OPJ_DATA_ROOT, opj_data_file from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG +from . import fixtures -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) class TestXML(unittest.TestCase): """Test suite for XML boxes.""" @@ -219,7 +220,7 @@ class TestJp2kBadXmlFile(unittest.TestCase): self.assertIsNone(jp2k.box[3].xml) -@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) class TestBadButRecoverableXmlFile(unittest.TestCase): """Test suite for XML box that is bad, but we can still recover the XML.""" diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 6c92ff9..48c0fdb 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -73,7 +73,7 @@ class SliceProtocolBase(unittest.TestCase): self.j2k_data = self.j2k.read() -@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) class TestSliceProtocolBaseWrite(SliceProtocolBase): def test_write_ellipsis(self): @@ -614,7 +614,7 @@ class TestJp2k(unittest.TestCase): jp2k = Jp2k(self.j2kfile) self.assertEqual(len(jp2k.box), 0) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_64bit_xl_field(self): """XL field should be supported""" # Verify that boxes with the XL field are properly read. @@ -648,7 +648,7 @@ class TestJp2k(unittest.TestCase): self.assertEqual(jp2k.box[4].offset, 3223) self.assertEqual(jp2k.box[4].length, 1133427 + 8) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_length_field_is_zero(self): """L=0 (length field in box header) is allowed""" # Verify that boxes with the L field as zero are correctly read. @@ -705,7 +705,7 @@ class TestJp2k(unittest.TestCase): j = Jp2k(self.j2kfile) self.assertEqual(j.box, []) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_uinf_ulst_url_boxes(self): """Verify that we can read UINF, ULST, and URL boxes""" # Verify that we can read UINF, ULST, and URL boxes. I don't have @@ -764,7 +764,7 @@ class TestJp2k(unittest.TestCase): self.assertEqual(jp2k.box[3].box[1].flag, (0, 0, 0)) self.assertEqual(jp2k.box[3].box[1].url, 'abcd') - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_xml_with_trailing_nulls(self): """ElementTree doesn't like trailing null chars after valid XML text""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: @@ -827,7 +827,7 @@ class TestJp2k(unittest.TestCase): @unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None, "Not supported with OpenJPEG {0}".format(openjpeg_version)) -@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) class TestJp2k_write(unittest.TestCase): """Write tests, can be run by versions 1.5+""" @@ -1015,7 +1015,7 @@ class TestJp2k_1_x(unittest.TestCase): class TestJp2k_2_0_official(unittest.TestCase): """Test suite to only be run on v2.0 official.""" - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_extra_components_on_v2(self): """Can only write 4 components on 2.0+, should error out otherwise.""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: @@ -1050,7 +1050,7 @@ class TestJp2k_2_0(unittest.TestCase): # End corner must be >= start corner j.read(area=(10, 10, 8, 8)) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_unrecognized_jp2_clrspace(self): """We only allow RGB and GRAYSCALE. Should error out with others""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: @@ -1059,7 +1059,7 @@ class TestJp2k_2_0(unittest.TestCase): data = np.zeros((128, 128, 3), dtype=np.uint8) j.write(data, colorspace='cmyk') - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_asoc_label_box(self): """Test asoc and label box""" # Construct a fake file with an asoc and a label box, as @@ -1121,7 +1121,7 @@ class TestJp2k_2_1(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_grey_with_extra_component(self): """version 2.0 cannot write gray + extra""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: @@ -1134,7 +1134,7 @@ class TestJp2k_2_1(unittest.TestCase): self.assertEqual(j.box[2].box[1].colorspace, glymur.core.GREYSCALE) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_rgb_with_extra_component(self): """v2.0+ should be able to write extra components""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: @@ -1147,7 +1147,7 @@ class TestJp2k_2_1(unittest.TestCase): self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_openjpeg_library_message(self): """Verify the error message produced by the openjpeg library""" # This will confirm that the error callback mechanism is working. @@ -1269,7 +1269,7 @@ class TestJp2kOpjDataRootWarnings(unittest.TestCase): class TestJp2kOpjDataRoot(unittest.TestCase): """These tests should be run by just about all configuration.""" - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) def test_irreversible(self): """Irreversible""" filename = opj_data_file('input/nonregression/issue141.rawl') diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 7e6357d..e0f947c 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -64,7 +64,7 @@ class CinemaBase(fixtures.MetadataBase): @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") -@unittest.skipIf(os.name == "nt", "no write support on windows, period") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) @unittest.skipIf(re.match(r'''(1|2.0.0)''', glymur.version.openjpeg_version) is not None, "Uses features not supported until 2.0.1") @@ -100,7 +100,7 @@ class WriteCinema(CinemaBase): @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") -@unittest.skipIf(os.name == "nt", "no write support on windows, period") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) @unittest.skipIf(re.match(r'''(1|2.0.0)''', glymur.version.openjpeg_version) is not None, "Uses features not supported until 2.0.1") @@ -194,7 +194,7 @@ class WriteCinemaWarns(CinemaBase): @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") -@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) @unittest.skipIf(not re.match("(1.5|2.0.0)", glymur.version.openjpeg_version), "Functionality implemented for 2.0.1") @unittest.skipIf(OPJ_DATA_ROOT is None, @@ -221,7 +221,7 @@ class TestSuiteNegative2pointzero(unittest.TestCase): @unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None, "Writing not supported until OpenJPEG 1.5") -@unittest.skipIf(os.name == "nt", "no write support on windows, period") +@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set")