============================= test session starts ============================== platform linux -- Python 3.10.13[pypy-7.3.15-final], pytest-8.0.2, pluggy-1.4.0 rootdir: /tmp/cramjam/cramjam-python plugins: hypothesis-6.98.13, xdist-3.5.0 created: 12/12 workers 12 workers [642 items] ........FF...F....F....F.F.F.F.....F.F..FF.F.F.F.FF..........F..FFF.F... [ 11%] FF......FF...FF..F..F..FF.F..F.F...FF...F....F......F......FF........F.. [ 22%] ...F..F.....F.......F....F....FFF.F.........F...F...F....FF..F......F... [ 33%] ....FF...FF.......F.F........FF..F.FF.F..FF....FF..F.F.F..FF..F...F..... [ 44%] FF.FFF.F..F.F.FF..F..F.FF.FF...F.FFF..FFF...F..F......FF.F..F.F.F.F....F [ 56%] F..FF..F.....F...F.F...FF.F......FF.......FFF..F...FF.F.....FF....FF.FF. [ 67%] ..F.F..FF.F.FFF.F.....F..F.F.F........FF..F.F...FF.F.....FF.F.F...F..F.. [ 78%] ..F......F..FF......F....F.F....F.F..FFF..F......F......FF.F....F..FF.F. [ 89%] FFFF.F.F.....FF..........F..F...................FFF...F..F........ [100%] =================================== FAILURES =================================== ______________________________ test_obj_api[File] ______________________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python tmpdir = local('/tmp/pytest-of-mgorny/pytest-3/popen-gw0/test_obj_api_File_0') Obj = @pytest.mark.parametrize("Obj", (File, Buffer)) def test_obj_api(tmpdir, Obj): if isinstance(Obj, File): buf = File(str(tmpdir.join("file.txt"))) else: buf = Buffer() assert buf.write(b"bytes") == 5 assert buf.tell() == 5 assert buf.seek(0) == 0 assert buf.read() == b"bytes" assert buf.seek(-1, 2) == 4 # set one byte backwards from end; position 4 assert buf.read() == b"s" assert buf.seek(-2, whence=1) == 3 # set two bytes from current (end): position 3 assert buf.read() == b"es" with pytest.raises(ValueError): buf.seek(1, 3) # only 0, 1, 2 are valid seek from positions for out in ( b"12345", bytearray(b"12345"), File(str(tmpdir.join("test.txt"))), Buffer(), ): buf.seek(0) expected = b"bytes" buf.readinto(out) # Will update the output buffer if isinstance(out, (File, Buffer)): out.seek(0) assert out.read() == expected elif isinstance(out, bytearray): assert out == bytearray(expected) else: > assert out == expected E AssertionError: assert b'12345' == b'bytes' E E At index 0 diff: b'1' != b'b' E Use -v to get more diff tests/test_rust_io.py:44: AssertionError _____________________________ test_obj_api[Buffer] _____________________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python tmpdir = local('/tmp/pytest-of-mgorny/pytest-3/popen-gw0/test_obj_api_Buffer_0') Obj = @pytest.mark.parametrize("Obj", (File, Buffer)) def test_obj_api(tmpdir, Obj): if isinstance(Obj, File): buf = File(str(tmpdir.join("file.txt"))) else: buf = Buffer() assert buf.write(b"bytes") == 5 assert buf.tell() == 5 assert buf.seek(0) == 0 assert buf.read() == b"bytes" assert buf.seek(-1, 2) == 4 # set one byte backwards from end; position 4 assert buf.read() == b"s" assert buf.seek(-2, whence=1) == 3 # set two bytes from current (end): position 3 assert buf.read() == b"es" with pytest.raises(ValueError): buf.seek(1, 3) # only 0, 1, 2 are valid seek from positions for out in ( b"12345", bytearray(b"12345"), File(str(tmpdir.join("test.txt"))), Buffer(), ): buf.seek(0) expected = b"bytes" buf.readinto(out) # Will update the output buffer if isinstance(out, (File, Buffer)): out.seek(0) assert out.read() == expected elif isinstance(out, bytearray): assert out == bytearray(expected) else: > assert out == expected E AssertionError: assert b'12345' == b'bytes' E E At index 0 diff: b'1' != b'b' E Use -v to get more diff tests/test_rust_io.py:44: AssertionError _______________ test_variants_compress_into[snappy-bytes-bytes] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[snappy-bytes-bytearray] ______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[snappy-bytes-numpy] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = 'numpy', output_type = raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ____________________ test_variants_different_dtypes[snappy] ____________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='snappy', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError _____________________ test_variants_different_dtypes[gzip] _____________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) E hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 0 valid examples in 5.32 seconds (1 invalid ones and 8 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters). E count | fraction | slowest draws (seconds) E arr | 9 | 100% | 0.467, 0.667, 1.003, 1.071, 1.364 E See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.too_slow to the suppress_health_check settings for this test. tests/test_variants.py:42: FailedHealthCheck _______________ test_variants_compress_into[snappy-bytes-Buffer] _______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[snappy-bytes-File] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ____________________ test_variants_different_dtypes[brotli] ____________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='brotli', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError _____________ test_variants_compress_into[snappy-bytes-memoryview] _____________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[brotli-memoryview-bytes] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) tests/test_variants.py:137: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 4 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_compress_into(variant_str='brotli', input_type=bytes, output_type=memoryview, raw_data=b'\x00', tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all')) produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = E output_type = , raw_data = b'\x00' E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_compress_into( E variant_str, input_type, output_type, raw_data, tmp_path_factory E ): E variant = getattr(cramjam, variant_str) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(raw_data, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(raw_data) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(raw_data) E input.seek(0) E else: E input = input_type(raw_data) E E compressed = variant.compress(raw_data) E compressed_len = len(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(compressed_len, dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * compressed_len) E E n_bytes = variant.compress_into(input, output) E assert n_bytes == compressed_len E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, compressed) E E AssertionError: assert False E E + where False = same_same(b';;;;;', cramjam.Buffer) E E tests/test_variants.py:137: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_compress_into[brotli-bytes-bytearray] ______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[bzip2-bytes-File] _________________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[brotli-memoryview-bytearray] ___________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[bzip2-memoryview-bytes] ______________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[brotli-memoryview-numpy] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = 'numpy', output_type = raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[brotli-memoryview-Buffer] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[bzip2-memoryview-bytearray] ____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ____________________ test_variants_different_dtypes[bzip2] _____________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='bzip2', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError _____________ test_variants_compress_into[brotli-memoryview-File] ______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[bzip2-memoryview-numpy] ______________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ___________________ test_variants_different_dtypes[deflate] ____________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='deflate', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError __________ test_variants_compress_into[brotli-memoryview-memoryview] ___________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[brotli-bytes-numpy] ________________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[snappy-memoryview-bytes] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[bzip2-bytes-memoryview] ______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[snappy-memoryview-bytearray] ___________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________________ test_variants_different_dtypes[lz4] ______________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='lz4', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError _____________ test_variants_compress_into[snappy-memoryview-numpy] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = 'numpy', output_type = raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[snappy-memoryview-Buffer] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'\xff\x06\x00\x00sNaPpY\x01\x05\x00\x00\xd2\x8f%I\x00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________________ test_variants_different_dtypes[zstd] _____________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='zstd', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError ________________ test_variants_compress_into[bzip2-bytes-bytes] ________________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;;;;;;;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[snappy-memoryview-File] ______________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[bzip2-memoryview-Buffer] _____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError __________ test_variants_compress_into[snappy-memoryview-memoryview] ___________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = , raw_data = b'\x00' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='snappy', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:137: AssertionError _____________________ test_variants_different_dtypes[lzma] _____________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma' @pytest.mark.parametrize("variant_str", VARIANTS) > @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) tests/test_variants.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', arr = array([], shape=(2, 0), dtype=bool) @pytest.mark.parametrize("variant_str", VARIANTS) @given(arr=st_np.arrays(st_np.scalar_dtypes(), shape=st.integers(0, int(1e4)))) def test_variants_different_dtypes(variant_str, arr): variant = getattr(cramjam, variant_str) compressed = variant.compress(arr) decompressed = variant.decompress(compressed) assert same_same(bytes(decompressed), arr.tobytes()) # And compress n dims > 1 if arr.shape[0] % 2 == 0: arr = arr.reshape((2, -1)) > compressed = variant.compress(arr) E TypeError: argument 'data': failed to extract enum BytesType ('Buffer | File | pybuffer') E - variant RustyBuffer (Buffer): TypeError: failed to extract field BytesType::RustyBuffer.0, caused by TypeError: 'ndarray' object cannot be converted to 'Buffer' E - variant RustyFile (File): TypeError: failed to extract field BytesType::RustyFile.0, caused by TypeError: 'ndarray' object cannot be converted to 'File' E - variant PyBuffer (pybuffer): TypeError: failed to extract field BytesType::PyBuffer.0, caused by BufferError: Buffer is not C contiguous E Falsifying example: test_variants_different_dtypes( E variant_str='lzma', E arr=array([], dtype=bool), E ) tests/test_variants.py:52: TypeError _______________ test_variants_compress_into[brotli-bytes-Buffer] _______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=None, _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[bzip2-memoryview-File] ______________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[bzip2-bytes-bytearray] ______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;;;;;;;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[brotli-bytes-bytes] ________________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[lz4-memoryview-numpy] _______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[brotli-bytes-File] ________________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[bzip2-memoryview-memoryview] ___________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[bzip2-bytes-numpy] ________________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;;;;;;;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[gzip-memoryview-bytearray] ____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[lz4-memoryview-Buffer] ______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[brotli-bytes-memoryview] _____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'0', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='brotli', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[bzip2-bytes-Buffer] ________________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b';;;;;;;;;;;;;;', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='bzip2', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _________________ test_variants_compress_into[lz4-bytes-bytes] _________________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = , output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[lz4-memoryview-File] _______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[gzip-memoryview-numpy] ______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[lz4-memoryview-bytes] _______________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[zstd-memoryview-File] _______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[zstd-memoryview-memoryview] ____________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[lz4-memoryview-memoryview] ____________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[lz4-bytes-bytearray] _______________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[lz4-memoryview-bytearray] _____________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) tests/test_variants.py:137: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 1 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_compress_into(variant_str='lz4', input_type=bytearray, output_type=memoryview, raw_data=b'', tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all')) produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = E output_type = , raw_data = b'' E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_compress_into( E variant_str, input_type, output_type, raw_data, tmp_path_factory E ): E variant = getattr(cramjam, variant_str) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(raw_data, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(raw_data) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(raw_data) E input.seek(0) E else: E input = input_type(raw_data) E E compressed = variant.compress(raw_data) E compressed_len = len(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(compressed_len, dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * compressed_len) E E n_bytes = variant.compress_into(input, output) E assert n_bytes == compressed_len E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, compressed) E E AssertionError: assert False E E + where False = same_same(b'000000000000000', cramjam.Buffer) E E tests/test_variants.py:137: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_compress_into[gzip-memoryview-Buffer] ______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[deflate-memoryview-bytes] _____________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError __________ test_variants_compress_into[deflate-memoryview-bytearray] ___________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _________________ test_variants_compress_into[lz4-bytes-numpy] _________________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[lzma-bytes-bytes] _________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[gzip-bytes-bytes] _________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[deflate-memoryview-numpy] _____________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = 'numpy' output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = 'numpy' output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[gzip-memoryview-File] _______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[snappy-bytes-bytes] _______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[snappy-bytes-bytearray] _____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[lzma-bytes-bytearray] _______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[gzip-memoryview-memoryview] ____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[snappy-bytes-numpy] _______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_compress_into[lz4-bytes-Buffer] _________________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[snappy-bytes-Buffer] ______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[snappy-bytes-File] _______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_compress_into[deflate-memoryview-Buffer] ____________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[snappy-bytes-memoryview] ____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[gzip-bytes-bytearray] _______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[gzip-memoryview-bytes] ______________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[lzma-memoryview-bytes] ______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[lzma-bytes-numpy] _________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[lzma-memoryview-bytearray] ____________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[deflate-memoryview-File] _____________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'\x03\x00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[zstd-memoryview-bytes] ______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[deflate-bytes-bytes] _______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_compress_into[zstd-memoryview-bytearray] ____________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError _________________ test_variants_compress_into[lz4-bytes-File] __________________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = , output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[snappy-memoryview-File] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x01') E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x01', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_compress_into[gzip-bytes-numpy] _________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[lzma-bytes-Buffer] ________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _________ test_variants_decompress_into[snappy-memoryview-memoryview] __________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xe4\xe4', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='snappy', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'snappy', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xe4\xe4', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky __________ test_variants_compress_into[deflate-memoryview-memoryview] __________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_compress_into[lzma-memoryview-numpy] ______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[brotli-bytes-bytes] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[brotli-bytes-bytearray] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[zstd-memoryview-numpy] ______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[brotli-bytes-numpy] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_compress_into[deflate-bytes-bytearray] _____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[brotli-bytes-Buffer] ______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _________________ test_variants_compress_into[lzma-bytes-File] _________________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = , output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_decompress_into[brotli-bytes-File] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[lz4-bytes-memoryview] _______________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lz4', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_compress_into[gzip-bytes-Buffer] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[lzma-memoryview-Buffer] ______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[brotli-bytes-memoryview] ____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_compress_into[zstd-bytes-bytes] _________________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_compress_into[zstd-memoryview-Buffer] ______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[snappy-memoryview-bytes] ____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'nn', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='snappy', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'snappy', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'nn', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky __________ test_variants_decompress_into[snappy-memoryview-bytearray] __________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xa5\xa5', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='snappy', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'snappy', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xa5\xa5', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_compress_into[lzma-bytes-memoryview] ______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_compress_into[deflate-bytes-numpy] _______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_decompress_into[bzip2-bytes-bytes] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _________________ test_variants_compress_into[gzip-bytes-File] _________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = , output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[snappy-memoryview-numpy] ____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'CC', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'snappy', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='snappy', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='snappy', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'snappy', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'CC', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[bzip2-bytes-bytearray] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[lzma-memoryview-File] _______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _______________ test_variants_decompress_into[bzip2-bytes-numpy] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[snappy-memoryview-Buffer] ____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x04\x04', b'\x00\x00') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'snappy', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky ______________ test_variants_compress_into[zstd-bytes-bytearray] _______________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ______________ test_variants_decompress_into[bzip2-bytes-Buffer] _______________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[bzip2-bytes-File] ________________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[bzip2-bytes-memoryview] _____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ______________ test_variants_compress_into[gzip-bytes-memoryview] ______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='gzip', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ___________ test_variants_compress_into[lzma-memoryview-memoryview] ____________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00000000000000000000000000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='lzma', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'', E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[brotli-memoryview-bytes] ____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'yy', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='brotli', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'yy', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_compress_into[deflate-bytes-Buffer] _______________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[bzip2-memoryview-Buffer] ____________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'<<', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='bzip2', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'bzip2', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'<<', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky __________ test_variants_decompress_into[brotli-memoryview-bytearray] __________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x8e\x8e', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='brotli', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x8e\x8e', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ________________ test_variants_compress_into[zstd-bytes-numpy] _________________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = 'numpy', output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_decompress_into[bzip2-memoryview-File] _____________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x01\x01', b'\x00\x00') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky ____________ test_variants_decompress_into[brotli-memoryview-numpy] ____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'FF', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='brotli', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'FF', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ________________ test_variants_decompress_into[lz4-bytes-File] _________________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[lz4-bytes-memoryview] ______________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[brotli-memoryview-Buffer] ____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x01') E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x01', E ) tests/test_variants.py:193: AssertionError __________ test_variants_decompress_into[bzip2-memoryview-memoryview] __________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00\x00', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='bzip2', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'bzip2', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x00\x00', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ________________ test_variants_decompress_into[lz4-bytes-bytes] ________________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[brotli-memoryview-File] _____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'yy', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='brotli', input_type=File, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'yy', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_decompress_into[lz4-bytes-bytearray] ______________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[lz4-memoryview-bytes] ______________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x02\x02', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lz4', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x02\x02', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _______________ test_variants_decompress_into[gzip-bytes-bytes] ________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_compress_into[deflate-bytes-File] ________________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ________________ test_variants_decompress_into[lz4-bytes-numpy] ________________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[gzip-bytes-bytearray] ______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_compress_into[zstd-bytes-Buffer] ________________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _________ test_variants_decompress_into[brotli-memoryview-memoryview] __________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'QQ', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'brotli', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='brotli', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='brotli', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'brotli', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'QQ', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _______________ test_variants_decompress_into[gzip-bytes-numpy] ________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[lz4-memoryview-bytearray] ____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'SS', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lz4', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'SS', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ____________ test_variants_decompress_into[bzip2-memoryview-bytes] _____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xee\xee', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='bzip2', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'bzip2', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xee\xee', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _______________ test_variants_decompress_into[lz4-bytes-Buffer] ________________ [gw9] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw9'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[gzip-bytes-Buffer] _______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_decompress_into[gzip-bytes-File] ________________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError __________ test_variants_decompress_into[bzip2-memoryview-bytearray] ___________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\xff' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\xff' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'gg', b'\x00\xff') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'bzip2', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky _____________ test_variants_decompress_into[gzip-bytes-memoryview] _____________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[lz4-memoryview-numpy] ______________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'jj', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lz4', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'jj', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ____________ test_variants_compress_into[deflate-bytes-memoryview] _____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'00', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='deflate', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[bzip2-memoryview-numpy] _____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'cc', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'bzip2', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='bzip2', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='bzip2', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'bzip2', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'cc', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _________________ test_variants_compress_into[zstd-bytes-File] _________________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = , output_type = raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError _____________ test_variants_decompress_into[lz4-memoryview-Buffer] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x81\x81', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lz4', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x81\x81', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_decompress_into[deflate-bytes-numpy] ______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[gzip-memoryview-bytes] _____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'bb', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'bb', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_decompress_into[lz4-memoryview-File] ______________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\xda\xda' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\xda\xda' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00\x00', b'\xda\xda') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lz4', input_type=File, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\xda\xda') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lz4', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\xda\xda', E ) E Failed to reproduce exception. Expected: E variant_str = 'lz4', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\xda\xda' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x00\x00', b'\xda\xda') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[deflate-bytes-Buffer] ______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[gzip-memoryview-File] ______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xcf\xcf', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type=File, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xcf\xcf', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ___________ test_variants_decompress_into[lz4-memoryview-memoryview] ___________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x05\x05', b'\x00\x00') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'lz4', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky ______________ test_variants_decompress_into[deflate-bytes-File] _______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[gzip-memoryview-bytearray] ___________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x06\x06', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x06\x06', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ___________ test_variants_decompress_into[deflate-bytes-memoryview] ____________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError __________ test_variants_decompress_into[gzip-memoryview-memoryview] ___________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xe2\xe2', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xe2\xe2', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_decompress_into[deflate-bytes-bytes] ______________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[gzip-memoryview-numpy] _____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xc3\xc3', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xc3\xc3', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ______________ test_variants_compress_into[zstd-bytes-memoryview] ______________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = , raw_data = b'' tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_compress_into( variant_str, input_type, output_type, raw_data, tmp_path_factory ): variant = getattr(cramjam, variant_str) # Setup input if input_type == "numpy": input = np.frombuffer(raw_data, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(raw_data) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(raw_data) input.seek(0) else: input = input_type(raw_data) compressed = variant.compress(raw_data) compressed_len = len(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(compressed_len, dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * compressed_len) n_bytes = variant.compress_into(input, output) assert n_bytes == compressed_len if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, compressed) E AssertionError: assert False E + where False = same_same(b'000000000', cramjam.Buffer) E Falsifying example: test_variants_compress_into( E variant_str='zstd', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'', # or any other generated value E ) tests/test_variants.py:137: AssertionError ____________ test_variants_decompress_into[deflate-bytes-bytearray] ____________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[zstd-bytes-numpy] ________________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ________________ test_variants_decompress_into[zstd-bytes-File] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[zstd-bytes-Buffer] _______________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[gzip-memoryview-Buffer] _____________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'oo', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'gzip', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='gzip', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='gzip', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'gzip', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'oo', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _________ test_variants_decompress_into[deflate-memoryview-memoryview] _________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x04\x04', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='deflate', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'deflate', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x04\x04', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[zstd-bytes-memoryview] _____________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[deflate-memoryview-bytes] ____________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'bb', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='deflate', input_type=bytes, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=bytes, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'deflate', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'bb', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ___________ test_variants_decompress_into[deflate-memoryview-numpy] ____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = 'numpy' output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = 'numpy' output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00\x00', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'deflate', input_type = 'numpy' output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='deflate', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'deflate', input_type = 'numpy' E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x00\x00', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _______________ test_variants_decompress_into[zstd-bytes-bytes] ________________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _________ test_variants_decompress_into[deflate-memoryview-bytearray] __________ [gw7] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x01') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw7'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x01', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[deflate-memoryview-Buffer] ___________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'vv', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='deflate', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'deflate', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'vv', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[zstd-bytes-bytearray] ______________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[deflate-memoryview-File] ____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'deflate', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x01') E Falsifying example: test_variants_decompress_into( E variant_str='deflate', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[lzma-bytes-bytes] ________________ [gw3] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=bytes, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw3'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ___________ test_variants_decompress_into[zstd-memoryview-bytearray] ___________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'$$', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='zstd', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'zstd', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'$$', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ________________ test_variants_decompress_into[lzma-bytes-File] ________________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = , output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=File, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[lzma-bytes-memoryview] _____________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=memoryview, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[lzma-bytes-bytearray] ______________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=bytearray, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError ____________ test_variants_decompress_into[zstd-memoryview-Buffer] _____________ [gw10] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xfe\xfe', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='zstd', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'zstd', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw10'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xfe\xfe', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[zstd-memoryview-File] ______________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'99', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='zstd', input_type=File, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'zstd', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'99', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[zstd-memoryview-numpy] _____________ [gw11] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'11', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'zstd', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='zstd', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'zstd', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw11'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'11', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _______________ test_variants_decompress_into[lzma-bytes-Buffer] _______________ [gw6] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all') raw_data = b'\x01' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00', b'\x01') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=Buffer, E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw6'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x01', E ) tests/test_variants.py:193: AssertionError _______________ test_variants_decompress_into[lzma-bytes-numpy] ________________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'0', b'\x00') E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type='numpy', E output_type=bytes, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00', E ) tests/test_variants.py:193: AssertionError _____________ test_variants_decompress_into[zstd-memoryview-bytes] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x00') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky __________ test_variants_decompress_into[zstd-memoryview-memoryview] ___________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xe5\xe5', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'zstd', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='zstd', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='zstd', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'zstd', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xe5\xe5', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ___________ test_variants_decompress_into[lzma-memoryview-bytearray] ___________ [gw8] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') raw_data = b':::' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') raw_data = b':::' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\x00\x00\x00', b':::') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 10 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lzma', input_type=bytearray, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), raw_data=b':::') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=bytearray, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all'), E raw_data=b':::', E ) E Failed to reproduce exception. Expected: E variant_str = 'lzma', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw8'), _retention_count=3, _retention_policy='all') E raw_data = b':::' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\x00\x00\x00', b':::') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[lzma-memoryview-numpy] _____________ [gw2] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'{{', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lzma', input_type = 'numpy', output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lzma', input_type='numpy', output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type='numpy', E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lzma', input_type = 'numpy', output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw2'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'{{', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky ____________ test_variants_decompress_into[lzma-memoryview-Buffer] _____________ [gw5] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'^^', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lzma', input_type=Buffer, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=Buffer, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lzma', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw5'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'^^', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[lzma-memoryview-File] ______________ [gw1] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'}}', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lzma', input_type=File, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=File, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lzma', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw1'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'}}', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky __________ test_variants_decompress_into[lzma-memoryview-memoryview] ___________ [gw0] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\xba\xba', b'\x00\x00') tests/test_variants.py:193: AssertionError The above exception was the direct cause of the following exception: variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = data = ConjectureData(VALID, 7 bytes, frozen) def execute_once( self, data, *, print_example=False, is_final=False, expected_failure=None, example_kwargs=None, ): """Run the test function once, using ``data`` as input. If the test raises an exception, it will propagate through to the caller of this method. Depending on its type, this could represent an ordinary test failure, or a fatal error, or a control exception. If this method returns normally, the test might have passed, or it might have placed ``data`` in an unsuccessful state and then swallowed the corresponding control exception. """ self.ever_executed = True data.is_find = self.is_find self._string_repr = "" text_repr = None if self.settings.deadline is None and not TESTCASE_CALLBACKS: test = self.test else: @proxies(self.test) def test(*args, **kwargs): arg_drawtime = math.fsum(data.draw_times.values()) start = time.perf_counter() try: result = self.test(*args, **kwargs) finally: finish = time.perf_counter() in_drawtime = math.fsum(data.draw_times.values()) - arg_drawtime runtime = datetime.timedelta(seconds=finish - start - in_drawtime) self._timing_features = { "execute:test": finish - start - in_drawtime, **data.draw_times, **data._stateful_run_times, } if (current_deadline := self.settings.deadline) is not None: if not is_final: current_deadline = (current_deadline // 4) * 5 if runtime >= current_deadline: raise DeadlineExceeded(runtime, self.settings.deadline) return result def run(data): # Set up dynamic context needed by a single test run. if self.stuff.selfy is not None: data.hypothesis_runner = self.stuff.selfy # Generate all arguments to the test function. args = self.stuff.args kwargs = dict(self.stuff.kwargs) if example_kwargs is None: kw, argslices = context.prep_args_kwargs_from_strategies( self.stuff.given_kwargs ) else: kw = example_kwargs argslices = {} kwargs.update(kw) if expected_failure is not None: nonlocal text_repr text_repr = repr_call(test, args, kwargs) if text_repr in self.xfail_example_reprs: warnings.warn( f"We generated {text_repr}, which seems identical " "to one of your `@example(...).xfail()` cases. " "Revise the strategy to avoid this overlap?", HypothesisWarning, # Checked in test_generating_xfailed_examples_warns! stacklevel=6, ) if print_example or current_verbosity() >= Verbosity.verbose: printer = RepresentationPrinter(context=context) if print_example: printer.text("Falsifying example:") else: printer.text("Trying example:") if self.print_given_args: printer.text(" ") printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) report(printer.getvalue()) if TESTCASE_CALLBACKS: printer = RepresentationPrinter(context=context) printer.repr_call( test.__name__, args, kwargs, force_split=True, arg_slices=argslices, leading_comment=( "# " + context.data.slice_comments[(0, 0)] if (0, 0) in context.data.slice_comments else None ), ) self._string_repr = printer.getvalue() self._jsonable_arguments = { **dict(enumerate(map(to_jsonable, args))), **{k: to_jsonable(v) for k, v in kwargs.items()}, } try: return test(*args, **kwargs) except TypeError as e: # If we sampled from a sequence of strategies, AND failed with a # TypeError, *AND that exception mentions SearchStrategy*, add a note: if "SearchStrategy" in str(e) and hasattr( data, "_sampled_from_all_strategies_elements_message" ): msg, format_arg = data._sampled_from_all_strategies_elements_message add_note(e, msg.format(format_arg)) raise finally: if parts := getattr(data, "_stateful_repr_parts", None): self._string_repr = "\n".join(parts) # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. with local_settings(self.settings): with deterministic_PRNG(): with BuildContext(data, is_final=is_final) as context: # Run the test function once, via the executor hook. # In most cases this will delegate straight to `run(data)`. result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error. if expected_failure is not None: exception, traceback = expected_failure if isinstance(exception, DeadlineExceeded) and ( runtime_secs := math.fsum( v for k, v in self._timing_features.items() if k.startswith("execute:") ) ): report( "Unreliable test timings! On an initial run, this " "test took %.2fms, which exceeded the deadline of " "%.2fms, but on a subsequent run it took %.2f ms, " "which did not. If you expect this sort of " "variability in your test timings, consider turning " "deadlines off for this test by setting deadline=None." % ( exception.runtime.total_seconds() * 1000, self.settings.deadline.total_seconds() * 1000, runtime_secs * 1000, ) ) else: report("Failed to reproduce exception. Expected: \n" + traceback) > raise Flaky( f"Hypothesis {text_repr} produces unreliable results: " "Falsified on the first call but did not on a subsequent one" ) from exception E hypothesis.errors.Flaky: Hypothesis test_variants_decompress_into(variant_str='lzma', input_type=memoryview, output_type=memoryview, tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), raw_data=b'\x00\x00') produces unreliable results: Falsified on the first call but did not on a subsequent one E Falsifying example: test_variants_decompress_into( E variant_str='lzma', E input_type=memoryview, E output_type=memoryview, E tmp_path_factory=TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all'), E raw_data=b'\x00\x00', E ) E Failed to reproduce exception. Expected: E variant_str = 'lzma', input_type = E output_type = E tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw0'), _retention_count=3, _retention_policy='all') E raw_data = b'\x00\x00' E E @pytest.mark.parametrize( E "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize( E "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) E ) E @pytest.mark.parametrize("variant_str", VARIANTS) E @given(raw_data=st.binary()) E def test_variants_decompress_into( E variant_str, input_type, output_type, tmp_path_factory, raw_data E ): E variant = getattr(cramjam, variant_str) E E compressed = variant.compress(raw_data) E E # Setup input E if input_type == "numpy": E input = np.frombuffer(compressed, dtype=np.uint8) E elif input_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") E path.touch() E input = cramjam.File(str(path)) E input.write(compressed) E input.seek(0) E elif input_type == cramjam.Buffer: E input = cramjam.Buffer() E input.write(compressed) E input.seek(0) E else: E input = input_type(compressed) E E # Setup output buffer E if output_type == "numpy": E output = np.zeros(len(raw_data), dtype=np.uint8) E elif output_type == cramjam.File: E path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") E path.touch() E output = cramjam.File(str(path)) E elif output_type == cramjam.Buffer: E output = cramjam.Buffer() E else: E output = output_type(b"0" * len(raw_data)) E E n_bytes = variant.decompress_into(input, output) E assert n_bytes == len(raw_data) E E if hasattr(output, "read"): E output.seek(0) E output = output.read() E elif hasattr(output, "tobytes"): E output = output.tobytes() E else: E output = bytes(output) E > assert same_same(output, raw_data) E E AssertionError: assert False E E + where False = same_same(b'\xba\xba', b'\x00\x00') E E tests/test_variants.py:193: AssertionError .venv/lib/pypy3.10/site-packages/hypothesis/core.py:970: Flaky _____________ test_variants_decompress_into[lzma-memoryview-bytes] _____________ [gw4] linux -- Python 3.10.13 /tmp/cramjam/cramjam-python/.venv/bin/python variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/pypy3.10/site-packages/hypothesis/core.py:831: in test result = self.test(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') raw_data = b'\x00\x00' @pytest.mark.parametrize( "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize( "output_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) @pytest.mark.parametrize("variant_str", VARIANTS) @given(raw_data=st.binary()) def test_variants_decompress_into( variant_str, input_type, output_type, tmp_path_factory, raw_data ): variant = getattr(cramjam, variant_str) compressed = variant.compress(raw_data) # Setup input if input_type == "numpy": input = np.frombuffer(compressed, dtype=np.uint8) elif input_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("input.txt") path.touch() input = cramjam.File(str(path)) input.write(compressed) input.seek(0) elif input_type == cramjam.Buffer: input = cramjam.Buffer() input.write(compressed) input.seek(0) else: input = input_type(compressed) # Setup output buffer if output_type == "numpy": output = np.zeros(len(raw_data), dtype=np.uint8) elif output_type == cramjam.File: path = tmp_path_factory.mktemp("tmp").joinpath("output.txt") path.touch() output = cramjam.File(str(path)) elif output_type == cramjam.Buffer: output = cramjam.Buffer() else: output = output_type(b"0" * len(raw_data)) n_bytes = variant.decompress_into(input, output) assert n_bytes == len(raw_data) if hasattr(output, "read"): output.seek(0) output = output.read() elif hasattr(output, "tobytes"): output = output.tobytes() else: output = bytes(output) > assert same_same(output, raw_data) E AssertionError: assert False E + where False = same_same(b'\t\t', b'\x00\x00') tests/test_variants.py:193: AssertionError During handling of the above exception, another exception occurred: variant_str = 'lzma', input_type = output_type = tmp_path_factory = TempPathFactory(_given_basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _trace=, _basetemp=PosixPath('/tmp/pytest-of-mgorny/pytest-3/popen-gw4'), _retention_count=3, _retention_policy='all') @pytest.mark.parametrize( > "input_type", (bytes, bytearray, "numpy", cramjam.Buffer, cramjam.File, memoryview) ) tests/test_variants.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = status = Status.INTERESTING interesting_origin = InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=()) def conclude_test(self, status, interesting_origin): """Says that ``status`` occurred at node ``node``. This updates the node if necessary and checks for consistency.""" if status == Status.OVERRUN: return i = self.__index_in_current_node node = self.__current_node if i < len(node.values) or isinstance(node.transition, Branch): inconsistent_generation() new_transition = Conclusion(status, interesting_origin) if node.transition is not None and node.transition != new_transition: # As an, I'm afraid, horrible bodge, we deliberately ignore flakiness # where tests go from interesting to valid, because it's much easier # to produce good error messages for these further up the stack. if isinstance(node.transition, Conclusion) and ( node.transition.status != Status.INTERESTING or new_transition.status != Status.VALID ): > raise Flaky( f"Inconsistent test results! Test case was {node.transition!r} " f"on first run but {new_transition!r} on second" ) E hypothesis.errors.Flaky: Inconsistent test results! Test case was Conclusion(status=Status.VALID, interesting_origin=None) on first run but Conclusion(status=Status.INTERESTING, interesting_origin=InterestingOrigin(exc_type=, filename='/tmp/cramjam/cramjam-python/tests/test_variants.py', lineno=193, context=(), group_elems=())) on second .venv/lib/pypy3.10/site-packages/hypothesis/internal/conjecture/datatree.py:998: Flaky =============================== warnings summary =============================== tests/test_variants.py::test_variants_different_dtypes[deflate] /tmp/cramjam/cramjam-python/.venv/lib/pypy3.10/site-packages/hypothesis/extra/numpy.py:243: RuntimeWarning: invalid value encountered in not_equal elem_changed = self._check_elements and val != result[idx] and val == val -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ FAILED tests/test_rust_io.py::test_obj_api[File] - AssertionError: assert b'1... FAILED tests/test_rust_io.py::test_obj_api[Buffer] - AssertionError: assert b... FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-numpy] FAILED tests/test_variants.py::test_variants_different_dtypes[snappy] - TypeE... FAILED tests/test_variants.py::test_variants_different_dtypes[gzip] - hypothe... FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-File] FAILED tests/test_variants.py::test_variants_different_dtypes[brotli] - TypeE... FAILED tests/test_variants.py::test_variants_compress_into[snappy-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-File] FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_different_dtypes[bzip2] - TypeEr... FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-numpy] FAILED tests/test_variants.py::test_variants_different_dtypes[deflate] - Type... FAILED tests/test_variants.py::test_variants_compress_into[brotli-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_different_dtypes[lz4] - TypeErro... FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_different_dtypes[zstd] - TypeErr... FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[snappy-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_different_dtypes[lzma] - TypeErr... FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-File] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[brotli-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[bzip2-bytes-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lz4-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-File] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[gzip-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-File] - ... FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-File] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[deflate-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-numpy] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-File] FAILED tests/test_variants.py::test_variants_compress_into[lz4-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[zstd-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lzma-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[snappy-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[gzip-bytes-memoryview] FAILED tests/test_variants.py::test_variants_compress_into[lzma-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-bytes] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-bytes] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-bytearray] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[brotli-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[deflate-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[bzip2-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[lz4-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-numpy] FAILED tests/test_variants.py::test_variants_compress_into[zstd-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[gzip-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[deflate-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-File] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-bytes-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-bytes] FAILED tests/test_variants.py::test_variants_decompress_into[zstd-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-bytearray] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-numpy] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-Buffer] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-File] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-memoryview] FAILED tests/test_variants.py::test_variants_decompress_into[lzma-memoryview-bytes] ============ 202 failed, 440 passed, 1 warning in 100.79s (0:01:40) ============