##// END OF EJS Templates
resourceutil: correct the root path for file based lookup under py2exe...
resourceutil: correct the root path for file based lookup under py2exe This silly copy/paste error caused "Mercurial" to be truncated from "C:\Program Files". The fact that "helptext" and "defaultrc" are now in a subpackage of "mercurial" added it back on, and everything seemed to work. But that broke if not installed to the default directory, and also caused TortoiseHg to look at Mercurial's config files instead of its own. Differential Revision: https://phab.mercurial-scm.org/D8054

File last commit:

r44605:5e84a96d default
r44678:9e367157 stable
Show More
test_buffer_util.py
146 lines | 5.0 KiB | text/x-python | PythonLexer
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 import struct
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 import unittest
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 import zstandard as zstd
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 from .common import TestCase
ss = struct.Struct("=QQ")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 class TestBufferWithSegments(TestCase):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 def test_arguments(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegments"):
self.skipTest("BufferWithSegments not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 with self.assertRaises(TypeError):
zstd.BufferWithSegments()
with self.assertRaises(TypeError):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 zstd.BufferWithSegments(b"foo")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
# Segments data should be a multiple of 16.
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(
ValueError, "segments array size is not a multiple of 16"
):
zstd.BufferWithSegments(b"foo", b"\x00\x00")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
def test_invalid_offset(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegments"):
self.skipTest("BufferWithSegments not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(
ValueError, "offset within segments array references memory"
):
zstd.BufferWithSegments(b"foo", ss.pack(0, 4))
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
def test_invalid_getitem(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegments"):
self.skipTest("BufferWithSegments not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 b = zstd.BufferWithSegments(b"foo", ss.pack(0, 3))
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(IndexError, "offset must be non-negative"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 test = b[-10]
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(IndexError, "offset must be less than 1"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 test = b[1]
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(IndexError, "offset must be less than 1"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 test = b[2]
def test_single(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegments"):
self.skipTest("BufferWithSegments not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 b = zstd.BufferWithSegments(b"foo", ss.pack(0, 3))
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 self.assertEqual(len(b), 1)
self.assertEqual(b.size, 3)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(b.tobytes(), b"foo")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
self.assertEqual(len(b[0]), 3)
self.assertEqual(b[0].offset, 0)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(b[0].tobytes(), b"foo")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
def test_multiple(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegments"):
self.skipTest("BufferWithSegments not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 b = zstd.BufferWithSegments(
b"foofooxfooxy", b"".join([ss.pack(0, 3), ss.pack(3, 4), ss.pack(7, 5)])
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 self.assertEqual(len(b), 3)
self.assertEqual(b.size, 12)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(b.tobytes(), b"foofooxfooxy")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(b[0].tobytes(), b"foo")
self.assertEqual(b[1].tobytes(), b"foox")
self.assertEqual(b[2].tobytes(), b"fooxy")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 class TestBufferWithSegmentsCollection(TestCase):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 def test_empty_constructor(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegmentsCollection"):
self.skipTest("BufferWithSegmentsCollection not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(ValueError, "must pass at least 1 argument"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 zstd.BufferWithSegmentsCollection()
def test_argument_validation(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegmentsCollection"):
self.skipTest("BufferWithSegmentsCollection not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(TypeError, "arguments must be BufferWithSegments"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 zstd.BufferWithSegmentsCollection(None)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(TypeError, "arguments must be BufferWithSegments"):
zstd.BufferWithSegmentsCollection(
zstd.BufferWithSegments(b"foo", ss.pack(0, 3)), None
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(
ValueError, "ZstdBufferWithSegments cannot be empty"
):
zstd.BufferWithSegmentsCollection(zstd.BufferWithSegments(b"", b""))
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
def test_length(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegmentsCollection"):
self.skipTest("BufferWithSegmentsCollection not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 b1 = zstd.BufferWithSegments(b"foo", ss.pack(0, 3))
b2 = zstd.BufferWithSegments(
b"barbaz", b"".join([ss.pack(0, 3), ss.pack(3, 3)])
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
c = zstd.BufferWithSegmentsCollection(b1)
self.assertEqual(len(c), 1)
self.assertEqual(c.size(), 3)
c = zstd.BufferWithSegmentsCollection(b2)
self.assertEqual(len(c), 2)
self.assertEqual(c.size(), 6)
c = zstd.BufferWithSegmentsCollection(b1, b2)
self.assertEqual(len(c), 3)
self.assertEqual(c.size(), 9)
def test_getitem(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 if not hasattr(zstd, "BufferWithSegmentsCollection"):
self.skipTest("BufferWithSegmentsCollection not available")
Gregory Szorc
zstandard: vendor python-zstandard 0.11...
r42237
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 b1 = zstd.BufferWithSegments(b"foo", ss.pack(0, 3))
b2 = zstd.BufferWithSegments(
b"barbaz", b"".join([ss.pack(0, 3), ss.pack(3, 3)])
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
c = zstd.BufferWithSegmentsCollection(b1, b2)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(IndexError, "offset must be less than 3"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 c[3]
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(IndexError, "offset must be less than 3"):
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 c[4]
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(c[0].tobytes(), b"foo")
self.assertEqual(c[1].tobytes(), b"bar")
self.assertEqual(c[2].tobytes(), b"baz")