Beispiel #1
0
class TestWebGatewayCacheTempFile(object):
    @pytest.fixture(autouse=True)
    def setUp(self, request):
        def fin():
            os.system("rm -fr test_cache")

        request.addfinalizer(fin)
        self.tmpfile = WebGatewayTempFile(tdir="test_cache")

    def testFilenameSize(self):
        """
        Make sure slashes, dashes, underscores and other chars don't mess
        things up.
        Also check for filename size limits.
        """
        fname = r'1/2_3!"\'#$%&()=@€£‰¶÷[]≠§±+*~^\,.;:'

        try:
            fpath, rpath, fobj = self.tmpfile.new(fname, key="specialchars")
        except Exception:
            raise
            pytest.fail(
                "WebGatewayTempFile.new not handling special" " characters properly"
            )
        # ext2/3/4 limit is 255 bytes, most others are equal to or larger
        fname = "a" * 384
        try:
            fpath, rpath, fobj = self.tmpfile.new(fname, key="longname")
            fobj.close()
            # is it keeping extensions properly?
            fpath, rpath, fobj = self.tmpfile.new("1" + fname + ".tif", key="longname")
            fobj.close()
            assert fpath[-5:] == "a.tif"
            fpath, rpath, fobj = self.tmpfile.new(
                "2" + fname + ".ome.tiff", key="longname"
            )
            fobj.close()
            assert fpath[-10:] == "a.ome.tiff"
            fpath, rpath, fobj = self.tmpfile.new(
                "3" + fname + "ome.tiff", key="longname"
            )
            fobj.close()
            assert fpath[-6:] == "a.tiff"
            fpath, rpath, fobj = self.tmpfile.new(
                "4" + fname + "somethingverylong.zip", key="longname"
            )
            fobj.close()
            assert fpath[-5:] == "a.zip"
            fpath, rpath, fobj = self.tmpfile.new(
                "5" + fname + ".tif.somethingverylong", key="longname"
            )
            fobj.close()
            assert fpath[-5:] == "aaaaa"
        except Exception:
            pytest.fail(
                "WebGatewayTempFile.new not handling long file names" " properly"
            )
Beispiel #2
0
class TestWebGatewayCacheTempFile(object):
    @pytest.fixture(autouse=True)
    def setUp(self, request):
        def fin():
            os.system('rm -fr test_cache')

        request.addfinalizer(fin)
        self.tmpfile = WebGatewayTempFile(tdir='test_cache')

    def testFilenameSize(self):
        """
        Make sure slashes, dashes, underscores and other chars don't mess
        things up.
        Also check for filename size limits.
        """
        fname = '1/2_3!"\'#$%&()=@€£‰¶÷[]≠§±+*~^\,.;:'

        try:
            fpath, rpath, fobj = self.tmpfile.new(fname, key='specialchars')
        except:
            raise
            pytest.fail('WebGatewayTempFile.new not handling special'
                        ' characters properly')
        # ext2/3/4 limit is 255 bytes, most others are equal to or larger
        fname = "a" * 384
        try:
            fpath, rpath, fobj = self.tmpfile.new(fname, key='longname')
            fobj.close()
            # is it keeping extensions properly?
            fpath, rpath, fobj = self.tmpfile.new("1" + fname + '.tif',
                                                  key='longname')
            fobj.close()
            assert fpath[-5:] == 'a.tif'
            fpath, rpath, fobj = self.tmpfile.new("2" + fname + '.ome.tiff',
                                                  key='longname')
            fobj.close()
            assert fpath[-10:] == 'a.ome.tiff'
            fpath, rpath, fobj = self.tmpfile.new("3" + fname + 'ome.tiff',
                                                  key='longname')
            fobj.close()
            assert fpath[-6:] == 'a.tiff'
            fpath, rpath, fobj = self.tmpfile.new("4" + fname +
                                                  'somethingverylong.zip',
                                                  key='longname')
            fobj.close()
            assert fpath[-5:] == 'a.zip'
            fpath, rpath, fobj = self.tmpfile.new("5" + fname +
                                                  '.tif.somethingverylong',
                                                  key='longname')
            fobj.close()
            assert fpath[-5:] == 'aaaaa'
        except:
            pytest.fail('WebGatewayTempFile.new not handling long file names'
                        ' properly')
Beispiel #3
0
    def setUp(self, request):
        def fin():
            os.system("rm -fr test_cache")

        request.addfinalizer(fin)
        self.tmpfile = WebGatewayTempFile(tdir="test_cache")