Beispiel #1
0
class Compression(unittest.TestCase):
    compression = None
    expected_suffix = ""
    expected_mimetype = "text/plain"
    dummytext = """For applications that require data compression, the functions in this module allow compression and decompression, using the zlib library. The zlib library has its own home page at http://www.zlib.net. There are known incompatibilities between the Python module and versions of the zlib library earlier than 1.1.3; 1.1.3 has a security vulnerability, so we recommend using 1.1.4 or later.

zlib’s functions have many options and often need to be used in a particular order. This documentation doesn’t attempt to cover all of the permutations; consult the zlib manual at http://www.zlib.net/manual.html for authoritative information.

For reading and writing .gz files see the gzip module.
"""

    def p(self, path):
        path = self.datadir + "/" + path
        return path.replace('/', '\\') if os.sep == '\\' else path

    def setUp(self):
        self.datadir = tempfile.mkdtemp()
        self.store = DocumentStore(self.datadir, compression=self.compression)

    def test_intermediate_path(self):
        self.assertEqual(
            self.p("intermediate/123/a.xml" + self.expected_suffix),
            self.store.intermediate_path('123/a'))

    def test_intermediate_path_selectsuffix(self):
        self.store.intermediate_suffixes = [".html", ".xhtml"]
        util.writefile(self.p("intermediate/123/a.html"), self.dummytext)
        self.assertEqual(
            self.p("intermediate/123/a.html") + self.expected_suffix,
            self.store.intermediate_path('123/a'))

    def test_open_intermediate_path(self):
        self.store.intermediate_suffixes = [".html", ".xhtml"]
        with self.store.open_intermediate("123/a", mode="w",
                                          suffix=".xhtml") as fp:
            fp.write(self.dummytext)
        filename = self.p("intermediate/123/a.xhtml" + self.expected_suffix)
        self.assertTrue(os.path.exists(filename))
        mimetype = util.runcmd("file -b --mime-type %s" % filename)[1]
        self.assertIn(mimetype.strip(), self.expected_mimetype)
        with self.store.open_intermediate("123/a") as fp:
            # note, open_intermediate should open the file with the
            # the .xhtml suffix automatically
            self.assertEqual(self.dummytext, fp.read())
Beispiel #2
0
class Compression(unittest.TestCase):
    compression = None
    expected_suffix = ""
    expected_mimetype = "text/plain"
    dummytext = """For applications that require data compression, the functions in this module allow compression and decompression, using the zlib library. The zlib library has its own home page at http://www.zlib.net. There are known incompatibilities between the Python module and versions of the zlib library earlier than 1.1.3; 1.1.3 has a security vulnerability, so we recommend using 1.1.4 or later.

zlib’s functions have many options and often need to be used in a particular order. This documentation doesn’t attempt to cover all of the permutations; consult the zlib manual at http://www.zlib.net/manual.html for authoritative information.

For reading and writing .gz files see the gzip module.
"""
    
    def p(self,path):
        path = self.datadir+"/"+path
        return path.replace('/', '\\') if os.sep == '\\' else path

    def setUp(self):
        self.datadir = tempfile.mkdtemp()
        self.store = DocumentStore(self.datadir, compression=self.compression)

    def test_intermediate_path(self):
        self.assertEqual(self.p("intermediate/123/a.xml" + self.expected_suffix),
                         self.store.intermediate_path('123/a'))

    def test_intermediate_path_selectsuffix(self):
        self.store.intermediate_suffixes = [".html", ".xhtml"]
        util.writefile(self.p("intermediate/123/a.html"), self.dummytext)
        self.assertEqual(self.p("intermediate/123/a.html") + self.expected_suffix,
                         self.store.intermediate_path('123/a'))

    def test_open_intermediate_path(self):
        self.store.intermediate_suffixes = [".html", ".xhtml"]
        with self.store.open_intermediate("123/a", mode="w", suffix=".xhtml") as fp:
            fp.write(self.dummytext)
        filename = self.p("intermediate/123/a.xhtml" + self.expected_suffix)
        self.assertTrue(os.path.exists(filename))
        mimetype = util.runcmd("file -b --mime-type %s" % filename)[1]
        self.assertIn(mimetype.strip(), self.expected_mimetype)
        with self.store.open_intermediate("123/a") as fp:
            # note, open_intermediate should open the file with the
            # the .xhtml suffix automatically
            self.assertEqual(self.dummytext, fp.read())