Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Python3 support

  • Loading branch information...
commit 91d4ee3e361335ee3349a719dc3d624561c5fe07 1 parent 2d16858
Felipe Cruz felipecruz authored

Showing 1 changed file with 75 additions and 0 deletions. Show diff stats Hide diff stats

  1. +75 0 test_snappy_py3.py
75 test_snappy_py3.py
... ... @@ -0,0 +1,75 @@
  1 +# Copyright (c) 2011, Andres Moreira <andres@andresmoreira.com>
  2 +# All rights reserved.
  3 +#
  4 +# Redistribution and use in source and binary forms, with or without
  5 +# modification, are permitted provided that the following conditions are met:
  6 +# * Redistributions of source code must retain the above copyright
  7 +# notice, this list of conditions and the following disclaimer.
  8 +# * Redistributions in binary form must reproduce the above copyright
  9 +# notice, this list of conditions and the following disclaimer in the
  10 +# documentation and/or other materials provided with the distribution.
  11 +# * Neither the name of the authors nor the
  12 +# names of its contributors may be used to endorse or promote products
  13 +# derived from this software without specific prior written permission.
  14 +#
  15 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18 +# DISCLAIMED. IN NO EVENT SHALL ANDRES MOREIRA BE LIABLE FOR ANY
  19 +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22 +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25 +
  26 +import os
  27 +import snappy
  28 +from unittest import TestCase
  29 +
  30 +class SnappyCompressionTest(TestCase):
  31 +
  32 + def test_simple_compress(self):
  33 + text = "hello world!".encode('utf-8')
  34 + compressed = snappy.compress(text)
  35 + self.assertEquals(text, snappy.uncompress(compressed))
  36 +
  37 + def test_moredata_compress(self):
  38 + text = "snappy +" * 1000 + " " + "by " * 1000 + " google"
  39 + text = text.encode('utf-8')
  40 + compressed = snappy.compress(text)
  41 + self.assertEquals(text, snappy.uncompress(compressed))
  42 +
  43 + def test_randombytes_compress(self):
  44 + _bytes = repr(os.urandom(1000)).encode('utf-8')
  45 + compressed = snappy.compress(_bytes)
  46 + self.assertEquals(_bytes, snappy.uncompress(compressed))
  47 +
  48 + def test_randombytes2_compress(self):
  49 + _bytes = str(os.urandom(10000)).encode('utf-8')
  50 + compressed = snappy.compress(_bytes)
  51 + self.assertEquals(_bytes, snappy.uncompress(compressed))
  52 +
  53 + def test_uncompress_error(self):
  54 + self.assertRaises(snappy.UncompressError, snappy.uncompress, "hoa".encode('utf-8'))
  55 +
  56 + def test_decompress(self):
  57 + # decompress == uncompress, just to support compatibility with zlib
  58 + text = "hello world!".encode('utf-8')
  59 + compressed = snappy.compress(text)
  60 + self.assertEquals(text, snappy.decompress(compressed))
  61 +
  62 +class SnappyValidBufferTest(TestCase):
  63 +
  64 + def test_valid_compressed_buffer(self):
  65 + text = "hello world!".encode('utf-8')
  66 + compressed = snappy.compress(text)
  67 + uncompressed = snappy.uncompress(compressed)
  68 + self.assertEquals(text == uncompressed, snappy.isValidCompressed(compressed))
  69 +
  70 + def test_invalid_compressed_buffer(self):
  71 + self.assertFalse(snappy.isValidCompressed("not compressed".encode('utf-8')))
  72 +
  73 +if __name__ == "__main__":
  74 + import unittest
  75 + unittest.main()

0 comments on commit 91d4ee3

Please sign in to comment.
Something went wrong with that request. Please try again.