Index: tools/grit/grit/format/gzip_string_unittest.py |
diff --git a/tools/grit/grit/format/gzip_string_unittest.py b/tools/grit/grit/format/gzip_string_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8df8b3b3f6a71b4687893030fe9d9b24ad9ab814 |
--- /dev/null |
+++ b/tools/grit/grit/format/gzip_string_unittest.py |
@@ -0,0 +1,62 @@ |
+# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+'''Unit tests for grit.format.gzip_string''' |
+ |
+import gzip |
+import io |
+import os |
+import sys |
+if __name__ == '__main__': |
+ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) |
+ |
+import unittest |
+ |
+from grit.format import gzip_string |
+ |
+ |
+class FormatGzipStringUnittest(unittest.TestCase): |
+ |
+ def testGzipStringRsyncable(self): |
+ # Can only test the rsyncable version on platforms which support rsyncable, |
+ # which at the moment is Linux. |
+ if sys.platform == 'linux2': |
+ header_begin = ('\x1f\x8b') # gzip first two bytes |
+ input = ('TEST STRING STARTING NOW' |
+ 'continuing' |
+ '<even more>' |
+ '<finished NOW>') |
+ |
+ compressed = gzip_string.GzipStringRsyncable(input) |
+ self.failUnless(header_begin == compressed[:2]) |
+ |
+ compressed_file = io.BytesIO() |
+ compressed_file.write(compressed) |
+ compressed_file.seek(0) |
+ |
+ with gzip.GzipFile(mode='rb', fileobj=compressed_file) as f: |
+ output = f.read() |
+ self.failUnless(output == input) |
+ |
+ def testGzipString(self): |
+ header_begin = '\x1f\x8b' # gzip first two bytes |
+ input = ('TEST STRING STARTING NOW' |
+ 'continuing' |
+ '<even more>' |
+ '<finished NOW>') |
+ |
+ compressed = gzip_string.GzipString(input) |
+ self.failUnless(header_begin == compressed[:2]) |
+ |
+ compressed_file = io.BytesIO() |
+ compressed_file.write(compressed) |
+ compressed_file.seek(0) |
+ |
+ with gzip.GzipFile(mode='rb', fileobj=compressed_file) as f: |
+ output = f.read() |
+ self.failUnless(output == input) |
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |