replaced windows temp file skip messages with a constant, closes #276

This commit is contained in:
jevans 2014-10-18 21:41:44 -04:00
commit 378cab4350
6 changed files with 39 additions and 33 deletions

View file

@ -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" msg = "Cannot run test with version {0} of python-six"
WARNING_INFRASTRUCTURE_MSG = msg.format(six.__version__) 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): class MetadataBase(unittest.TestCase):
""" """
Base class for testing metadata. Base class for testing metadata.

View file

@ -25,7 +25,11 @@ else:
import glymur import glymur
from glymur import Jp2k 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, @unittest.skipIf(sys.hexversion < 0x03020000,
"TemporaryDirectory introduced in 3.2.") "TemporaryDirectory introduced in 3.2.")
@ -71,7 +75,7 @@ class TestSuite(unittest.TestCase):
Jp2k(self.jp2file) Jp2k(self.jp2file)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) @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): def test_xdg_env_config_file_is_bad(self):
"""A non-existant library location should be rejected.""" """A non-existant library location should be rejected."""
with tempfile.TemporaryDirectory() as tdir: with tempfile.TemporaryDirectory() as tdir:
@ -122,7 +126,7 @@ class TestConfig(unittest.TestCase):
with self.assertRaises(glymur.jp2k.LibraryNotFoundError): with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
glymur.Jp2k(self.jp2file).read_bands() 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): def test_write_without_library(self):
"""Don't have openjpeg libraries? Must error out. """Don't have openjpeg libraries? Must error out.
""" """

View file

@ -37,7 +37,7 @@ from glymur.core import RED, GREEN, BLUE, GREY, WHOLE_IMAGE
from .fixtures import ( from .fixtures import (
WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG, WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG,
MetadataBase WINDOWS_TMP_FILE_MSG, MetadataBase
) )
try: try:
@ -54,7 +54,7 @@ def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite('glymur.jp2box')) tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
return tests 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): class TestDataEntryURL(unittest.TestCase):
"""Test suite for DataEntryURL boxes.""" """Test suite for DataEntryURL boxes."""
def setUp(self): def setUp(self):
@ -122,7 +122,7 @@ class TestDataEntryURL(unittest.TestCase):
@unittest.skipIf(re.match(r'''(1|2.0.0)''', @unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None, glymur.version.openjpeg_version) is not None,
"Not supported until 2.1") "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): class TestChannelDefinition(unittest.TestCase):
"""Test suite for channel definition boxes.""" """Test suite for channel definition boxes."""
@ -434,8 +434,7 @@ class TestColourSpecificationBox(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
@unittest.skipIf(os.name == "nt", @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG)
"Problems using NamedTemporaryFile on windows.")
def test_colr_with_out_enum_cspace(self): def test_colr_with_out_enum_cspace(self):
"""must supply an enumerated colorspace when writing""" """must supply an enumerated colorspace when writing"""
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
@ -446,7 +445,7 @@ class TestColourSpecificationBox(unittest.TestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
j2k.wrap(tfile.name, boxes=boxes) 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): def test_missing_colr_box(self):
"""jp2h must have a colr box""" """jp2h must have a colr box"""
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
@ -456,7 +455,7 @@ class TestColourSpecificationBox(unittest.TestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
j2k.wrap(tfile.name, boxes=boxes) 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): def test_bad_approx_jp2_field(self):
"""JP2 has requirements for approx field""" """JP2 has requirements for approx field"""
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
@ -517,8 +516,7 @@ class TestColourSpecificationBox(unittest.TestCase):
colr.write(tfile) colr.write(tfile)
@unittest.skipIf(os.name == "nt", @unittest.skipIf(os.name == "nt", WINDOWS_TMP_FILE_MSG)
"Problems using NamedTemporaryFile on windows.")
class TestPaletteBox(unittest.TestCase): class TestPaletteBox(unittest.TestCase):
"""Test suite for pclr box instantiation.""" """Test suite for pclr box instantiation."""
@ -560,7 +558,7 @@ class TestPaletteBox(unittest.TestCase):
pclr.write(tfile) 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): class TestAppend(unittest.TestCase):
"""Tests for append method.""" """Tests for append method."""
@ -653,7 +651,7 @@ class TestAppend(unittest.TestCase):
jp2.append(uuidbox) 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): class TestWrap(unittest.TestCase):
"""Tests for wrap method.""" """Tests for wrap method."""

View file

@ -41,8 +41,9 @@ from glymur.jp2box import JPEG2000SignatureBox
from .fixtures import OPJ_DATA_ROOT, opj_data_file from .fixtures import OPJ_DATA_ROOT, opj_data_file
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG 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): class TestXML(unittest.TestCase):
"""Test suite for XML boxes.""" """Test suite for XML boxes."""
@ -219,7 +220,7 @@ class TestJp2kBadXmlFile(unittest.TestCase):
self.assertIsNone(jp2k.box[3].xml) 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): class TestBadButRecoverableXmlFile(unittest.TestCase):
"""Test suite for XML box that is bad, but we can still recover the XML.""" """Test suite for XML box that is bad, but we can still recover the XML."""

View file

@ -73,7 +73,7 @@ class SliceProtocolBase(unittest.TestCase):
self.j2k_data = self.j2k.read() 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): class TestSliceProtocolBaseWrite(SliceProtocolBase):
def test_write_ellipsis(self): def test_write_ellipsis(self):
@ -614,7 +614,7 @@ class TestJp2k(unittest.TestCase):
jp2k = Jp2k(self.j2kfile) jp2k = Jp2k(self.j2kfile)
self.assertEqual(len(jp2k.box), 0) 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): def test_64bit_xl_field(self):
"""XL field should be supported""" """XL field should be supported"""
# Verify that boxes with the XL field are properly read. # 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].offset, 3223)
self.assertEqual(jp2k.box[4].length, 1133427 + 8) 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): def test_length_field_is_zero(self):
"""L=0 (length field in box header) is allowed""" """L=0 (length field in box header) is allowed"""
# Verify that boxes with the L field as zero are correctly read. # Verify that boxes with the L field as zero are correctly read.
@ -705,7 +705,7 @@ class TestJp2k(unittest.TestCase):
j = Jp2k(self.j2kfile) j = Jp2k(self.j2kfile)
self.assertEqual(j.box, []) 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): 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"""
# Verify that we can read UINF, ULST, and URL boxes. I don't have # 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].flag, (0, 0, 0))
self.assertEqual(jp2k.box[3].box[1].url, 'abcd') 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): def test_xml_with_trailing_nulls(self):
"""ElementTree doesn't like trailing null chars after valid XML text""" """ElementTree doesn't like trailing null chars after valid XML text"""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: 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, @unittest.skipIf(re.match('1.[0-4]', openjpeg_version) is not None,
"Not supported with OpenJPEG {0}".format(openjpeg_version)) "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): class TestJp2k_write(unittest.TestCase):
"""Write tests, can be run by versions 1.5+""" """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): class TestJp2k_2_0_official(unittest.TestCase):
"""Test suite to only be run on v2.0 official.""" """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): def test_extra_components_on_v2(self):
"""Can only write 4 components on 2.0+, should error out otherwise.""" """Can only write 4 components on 2.0+, should error out otherwise."""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
@ -1050,7 +1050,7 @@ class TestJp2k_2_0(unittest.TestCase):
# End corner must be >= start corner # End corner must be >= start corner
j.read(area=(10, 10, 8, 8)) 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): def test_unrecognized_jp2_clrspace(self):
"""We only allow RGB and GRAYSCALE. Should error out with others""" """We only allow RGB and GRAYSCALE. Should error out with others"""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: 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) data = np.zeros((128, 128, 3), dtype=np.uint8)
j.write(data, colorspace='cmyk') 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): def test_asoc_label_box(self):
"""Test asoc and label box""" """Test asoc and label box"""
# Construct a fake file with an asoc and a label box, as # 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): def tearDown(self):
pass 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): def test_grey_with_extra_component(self):
"""version 2.0 cannot write gray + extra""" """version 2.0 cannot write gray + extra"""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: 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, self.assertEqual(j.box[2].box[1].colorspace,
glymur.core.GREYSCALE) 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): def test_rgb_with_extra_component(self):
"""v2.0+ should be able to write extra components""" """v2.0+ should be able to write extra components"""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: 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) self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) @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): def test_openjpeg_library_message(self):
"""Verify the error message produced by the openjpeg library""" """Verify the error message produced by the openjpeg library"""
# This will confirm that the error callback mechanism is working. # This will confirm that the error callback mechanism is working.
@ -1269,7 +1269,7 @@ class TestJp2kOpjDataRootWarnings(unittest.TestCase):
class TestJp2kOpjDataRoot(unittest.TestCase): class TestJp2kOpjDataRoot(unittest.TestCase):
"""These tests should be run by just about all configuration.""" """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): def test_irreversible(self):
"""Irreversible""" """Irreversible"""
filename = opj_data_file('input/nonregression/issue141.rawl') filename = opj_data_file('input/nonregression/issue141.rawl')

View file

@ -64,7 +64,7 @@ class CinemaBase(fixtures.MetadataBase):
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage") "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)''', @unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None, glymur.version.openjpeg_version) is not None,
"Uses features not supported until 2.0.1") "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(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage") "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)''', @unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None, glymur.version.openjpeg_version) is not None,
"Uses features not supported until 2.0.1") "Uses features not supported until 2.0.1")
@ -194,7 +194,7 @@ class WriteCinemaWarns(CinemaBase):
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage") "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), @unittest.skipIf(not re.match("(1.5|2.0.0)", glymur.version.openjpeg_version),
"Functionality implemented for 2.0.1") "Functionality implemented for 2.0.1")
@unittest.skipIf(OPJ_DATA_ROOT is None, @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, @unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None,
"Writing not supported until OpenJPEG 1.5") "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(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(OPJ_DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set") "OPJ_DATA_ROOT environment variable not set")