sabctools 8.2.0__tar.gz → 8.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. {sabctools-8.2.0/sabctools.egg-info → sabctools-8.2.2}/PKG-INFO +1 -1
  2. {sabctools-8.2.0 → sabctools-8.2.2/sabctools.egg-info}/PKG-INFO +1 -1
  3. {sabctools-8.2.0 → sabctools-8.2.2}/sabctools.egg-info/SOURCES.txt +9 -1
  4. {sabctools-8.2.0 → sabctools-8.2.2}/setup.py +2 -9
  5. {sabctools-8.2.0 → sabctools-8.2.2}/src/sabctools.h +1 -1
  6. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/common.h +0 -4
  7. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc.h +1 -1
  8. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_arm_pmull.cc +1 -1
  9. sabctools-8.2.2/tests/test.py +22 -0
  10. sabctools-8.2.2/tests/test_crc32.py +80 -0
  11. sabctools-8.2.2/tests/test_decoder.py +115 -0
  12. sabctools-8.2.2/tests/test_encoder.py +7 -0
  13. sabctools-8.2.2/tests/test_sparse.py +45 -0
  14. sabctools-8.2.2/tests/test_unlocked_ssl.py +340 -0
  15. sabctools-8.2.2/tests/test_utils.py +16 -0
  16. sabctools-8.2.2/tests/testsupport.py +184 -0
  17. {sabctools-8.2.0 → sabctools-8.2.2}/LICENSE.md +0 -0
  18. {sabctools-8.2.0 → sabctools-8.2.2}/MANIFEST.in +0 -0
  19. {sabctools-8.2.0 → sabctools-8.2.2}/README.md +0 -0
  20. {sabctools-8.2.0 → sabctools-8.2.2}/pyproject.toml +0 -0
  21. {sabctools-8.2.0 → sabctools-8.2.2}/sabctools.egg-info/dependency_links.txt +0 -0
  22. {sabctools-8.2.0 → sabctools-8.2.2}/sabctools.egg-info/top_level.txt +0 -0
  23. {sabctools-8.2.0 → sabctools-8.2.2}/setup.cfg +0 -0
  24. {sabctools-8.2.0 → sabctools-8.2.2}/src/__init__.py +0 -0
  25. {sabctools-8.2.0 → sabctools-8.2.2}/src/crc32.cc +0 -0
  26. {sabctools-8.2.0 → sabctools-8.2.2}/src/crc32.h +0 -0
  27. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/AUTHORS +0 -0
  28. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/COPYING +0 -0
  29. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/ChangeLog +0 -0
  30. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/INSTALL +0 -0
  31. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/LICENSE +0 -0
  32. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/Makefile +0 -0
  33. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/Makefile.am +0 -0
  34. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/Makefile.in +0 -0
  35. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/Makefile.win +0 -0
  36. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/NEWS +0 -0
  37. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/README +0 -0
  38. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/aclocal.m4 +0 -0
  39. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/autogen.sh +0 -0
  40. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/base_types.h +0 -0
  41. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/crc32c_sse4.cc +0 -0
  42. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/crc32c_sse4.h +0 -0
  43. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/crc32c_sse4_intrin.h +0 -0
  44. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/crc_casts.h +0 -0
  45. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/generic_crc.h +0 -0
  46. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/gf_util.h +0 -0
  47. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/multiword_128_64_gcc_amd64_sse2.cc +0 -0
  48. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/multiword_64_64_cl_i386_mmx.cc +0 -0
  49. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/multiword_64_64_gcc_amd64_asm.cc +0 -0
  50. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/multiword_64_64_gcc_i386_mmx.cc +0 -0
  51. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/multiword_64_64_intrinsic_i386_mmx.cc +0 -0
  52. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/platform.h +0 -0
  53. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/protected_crc.h +0 -0
  54. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/rolling_crc.h +0 -0
  55. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/std_headers.h +0 -0
  56. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/code/uint128_sse2.h +0 -0
  57. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/config.h.in +0 -0
  58. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/configure +0 -0
  59. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/configure.ac +0 -0
  60. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/depcomp +0 -0
  61. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/examples/interface.cc +0 -0
  62. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/examples/interface.h +0 -0
  63. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/examples/usage.cc +0 -0
  64. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/install-sh +0 -0
  65. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/missing +0 -0
  66. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/aligned_alloc.h +0 -0
  67. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/bob_jenkins_rng.h +0 -0
  68. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/rdtsc.h +0 -0
  69. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/set_hi_pri.c +0 -0
  70. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/unittest.cc +0 -0
  71. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/unittest.h +0 -0
  72. {sabctools-8.2.0 → sabctools-8.2.2}/src/crcutil-1.0/tests/unittest_helper.h +0 -0
  73. {sabctools-8.2.0 → sabctools-8.2.2}/src/py.typed +0 -0
  74. {sabctools-8.2.0 → sabctools-8.2.2}/src/sabctools.cc +0 -0
  75. {sabctools-8.2.0 → sabctools-8.2.2}/src/sabctools.pyi +0 -0
  76. {sabctools-8.2.0 → sabctools-8.2.2}/src/sparse.cc +0 -0
  77. {sabctools-8.2.0 → sabctools-8.2.2}/src/sparse.h +0 -0
  78. {sabctools-8.2.0 → sabctools-8.2.2}/src/unlocked_ssl.cc +0 -0
  79. {sabctools-8.2.0 → sabctools-8.2.2}/src/unlocked_ssl.h +0 -0
  80. {sabctools-8.2.0 → sabctools-8.2.2}/src/utils.cc +0 -0
  81. {sabctools-8.2.0 → sabctools-8.2.2}/src/utils.h +0 -0
  82. {sabctools-8.2.0 → sabctools-8.2.2}/src/yenc.cc +0 -0
  83. {sabctools-8.2.0 → sabctools-8.2.2}/src/yenc.h +0 -0
  84. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc.cc +0 -0
  85. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_arm.cc +0 -0
  86. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_common.h +0 -0
  87. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_folding.cc +0 -0
  88. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_folding_256.cc +0 -0
  89. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/crc_riscv.cc +0 -0
  90. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder.cc +0 -0
  91. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder.h +0 -0
  92. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_avx.cc +0 -0
  93. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_avx2.cc +0 -0
  94. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_avx2_base.h +0 -0
  95. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_common.h +0 -0
  96. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_neon.cc +0 -0
  97. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_neon64.cc +0 -0
  98. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_rvv.cc +0 -0
  99. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_sse2.cc +0 -0
  100. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_sse_base.h +0 -0
  101. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_ssse3.cc +0 -0
  102. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/decoder_vbmi2.cc +0 -0
  103. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder.cc +0 -0
  104. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder.h +0 -0
  105. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_avx.cc +0 -0
  106. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_avx2.cc +0 -0
  107. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_avx_base.h +0 -0
  108. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_common.h +0 -0
  109. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_neon.cc +0 -0
  110. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_rvv.cc +0 -0
  111. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_sse2.cc +0 -0
  112. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_sse_base.h +0 -0
  113. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_ssse3.cc +0 -0
  114. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/encoder_vbmi2.cc +0 -0
  115. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/hedley.h +0 -0
  116. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/platform.cc +0 -0
  117. {sabctools-8.2.0 → sabctools-8.2.2}/src/yencode/stdint.h +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sabctools
3
- Version: 8.2.0
3
+ Version: 8.2.2
4
4
  Summary: C implementations of functions for use within SABnzbd
5
5
  Home-page: https://github.com/sabnzbd/sabctools/
6
6
  Author: Safihre
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sabctools
3
- Version: 8.2.0
3
+ Version: 8.2.2
4
4
  Summary: C implementations of functions for use within SABnzbd
5
5
  Home-page: https://github.com/sabnzbd/sabctools/
6
6
  Author: Safihre
@@ -104,4 +104,12 @@ src/yencode/encoder_ssse3.cc
104
104
  src/yencode/encoder_vbmi2.cc
105
105
  src/yencode/hedley.h
106
106
  src/yencode/platform.cc
107
- src/yencode/stdint.h
107
+ src/yencode/stdint.h
108
+ tests/test.py
109
+ tests/test_crc32.py
110
+ tests/test_decoder.py
111
+ tests/test_encoder.py
112
+ tests/test_sparse.py
113
+ tests/test_unlocked_ssl.py
114
+ tests/test_utils.py
115
+ tests/testsupport.py
@@ -124,13 +124,6 @@ class SABCToolsBuild(build_ext):
124
124
  # Verify specific flags for ARM chips
125
125
  # macOS M1 do not need any flags, they support everything
126
126
  if IS_ARM and not IS_MACOS:
127
- if not autoconf_check(self.compiler, include_check="sys/auxv.h"):
128
- # We only tested this for GCC, might still be valid on MS-ARM compiler (see #38)
129
- if autoconf_check(self.compiler, define_check="__GNUC__"):
130
- log.info("==> On GGC and sys/auxv.h not available, setting UNSUPPORTED_PLATFORM_ARM=1")
131
- ext.define_macros.append(("UNSUPPORTED_PLATFORM_ARM", "1"))
132
- gcc_macros.append(("UNSUPPORTED_PLATFORM_ARM", "1"))
133
- IS_ARM = False
134
127
  if not autoconf_check(self.compiler, define_check="__aarch64__"):
135
128
  log.info("==> __aarch64__ not available, disabling 64bit extensions")
136
129
  IS_AARCH64 = False
@@ -288,12 +281,12 @@ class SABCToolsBuild(build_ext):
288
281
  {
289
282
  "sources": ["src/yencode/encoder_rvv.cc", "src/yencode/decoder_rvv.cc"],
290
283
  "depends": srcdeps_enc_common + srcdeps_dec_common,
291
- "gcc_rv_flags": gcc_rvv_flags,
284
+ "gcc_flags": gcc_rvv_flags,
292
285
  },
293
286
  {
294
287
  "sources": ["src/yencode/crc_riscv.cc"],
295
288
  "depends": srcdeps_crc_common,
296
- "gcc_rv_flags": gcc_rvzbkc_flags,
289
+ "gcc_flags": gcc_rvzbkc_flags,
297
290
  },
298
291
  {
299
292
  "sources": [
@@ -22,6 +22,6 @@
22
22
  #include <string.h>
23
23
 
24
24
  /* Version information */
25
- #define SABCTOOLS_VERSION "8.2.0"
25
+ #define SABCTOOLS_VERSION "8.2.2"
26
26
 
27
27
  PyMODINIT_FUNC PyInit_sabctools(void);
@@ -34,10 +34,6 @@
34
34
  #define PLATFORM_ARM 1
35
35
  #endif
36
36
 
37
- #if defined(UNSUPPORTED_PLATFORM_ARM)
38
- #undef PLATFORM_ARM
39
- #endif
40
-
41
37
  #include <stdlib.h>
42
38
  #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
43
39
  // MSVC doesn't support C11 aligned_alloc: https://stackoverflow.com/a/62963007
@@ -23,7 +23,7 @@ static inline int crc32_isa_level() {
23
23
 
24
24
  // computes `n % 0xffffffff` (well, almost), using some bit-hacks
25
25
  static inline uint32_t crc32_powmod(uint64_t n) {
26
- #ifdef __GNUC__
26
+ #if defined(__GNUC__) && (__GNUC__ >= 5 || (defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ > 3))))
27
27
  unsigned res;
28
28
  unsigned carry = __builtin_uadd_overflow(n >> 32, n, &res);
29
29
  res += carry;
@@ -207,7 +207,7 @@ static uint32_t crc32_shift_pmull(uint32_t crc1, uint32_t n) {
207
207
  void RapidYenc::crc_pmull_set_funcs() {
208
208
  _crc32_multiply = &crc32_multiply_pmull;
209
209
  _crc32_shift = &crc32_shift_pmull;
210
- _crc32_isa &= ISA_FEATURE_PMULL;
210
+ _crc32_isa |= ISA_FEATURE_PMULL;
211
211
  }
212
212
 
213
213
  #else
@@ -0,0 +1,22 @@
1
+ import time
2
+ import ssl
3
+ import sabctools
4
+ import socket
5
+ import time
6
+
7
+
8
+ hostname = "eunews.frugalusenet.com"
9
+ context = ssl.create_default_context()
10
+
11
+ print(sabctools.openssl_linked)
12
+
13
+ buffer = bytearray(100)
14
+ bufferview = memoryview(buffer)
15
+
16
+ with socket.create_connection((hostname, 563)) as sock:
17
+ with context.wrap_socket(sock, server_hostname=hostname) as ssock:
18
+ ssock.setblocking(False)
19
+ time.sleep(1)
20
+ print(ssock.version())
21
+ print(sabctools.unlocked_ssl_recv_into(ssock._sslobj, bufferview[99:]))
22
+ print(buffer)
@@ -0,0 +1,80 @@
1
+ import pytest
2
+ import sabctools
3
+
4
+
5
+ @pytest.mark.parametrize(
6
+ "crc1,crc2,len2,expected",
7
+ [
8
+ (0, 0, 0, 0),
9
+ (4294967295, 0, 0, 4294967295),
10
+ (0, 4294967295, 0, 4294967295),
11
+ (4294967295, 4294967295, 0, 0),
12
+ (4, 16, 256, 2385497022),
13
+ (100, 200, 300, 1009376567),
14
+ (0, 0, 18446744073709551615, 0),
15
+ (4294967295, 4294967295, 18446744073709551615, 0),
16
+ (0, 100, 1234567890123, 100),
17
+ (100, 0, 1234567890123, 1829446317),
18
+ ],
19
+ )
20
+ def test_crc32_combine_expected(crc1, crc2, len2, expected):
21
+ assert sabctools.crc32_combine(crc1, crc2, len2) == expected
22
+
23
+
24
+ @pytest.mark.parametrize(
25
+ "crc1,crc2,expected",
26
+ [
27
+ (0, 0, 0),
28
+ (4294967295, 0, 0),
29
+ (0, 4294967295, 0),
30
+ (4294967295, 4294967295, 1048090088),
31
+ (100, 200, 4155012749),
32
+ ],
33
+ )
34
+ def test_crc32_multiply_expected(crc1, crc2, expected):
35
+ assert sabctools.crc32_multiply(crc1, crc2) == expected
36
+
37
+
38
+ @pytest.mark.parametrize(
39
+ "crc1,zeroes,expected",
40
+ [
41
+ (0, 0, 0),
42
+ (4294967295, 0, 4294967295),
43
+ (4294967295, 4294967295, 4294967295),
44
+ (100, 200, 1523530880),
45
+ (0, 18446744073709551615, 0),
46
+ (4294967295, 18446744073709551615, 4294967295),
47
+ (100, 1234567890123, 980217485),
48
+ ],
49
+ )
50
+ def test_crc32_zero_unpad_expected(crc1, zeroes, expected):
51
+ assert sabctools.crc32_zero_unpad(crc1, zeroes) == expected
52
+
53
+
54
+ @pytest.mark.parametrize(
55
+ "n,expected",
56
+ [
57
+ (0, 2147483648),
58
+ (1, 1073741824),
59
+ (8, 8388608),
60
+ (30, 2),
61
+ (31, 1),
62
+ (4294967295, 2147483648),
63
+ (4294967296, 1073741824), # 1
64
+ ],
65
+ )
66
+ def test_crc32_xpown_expected(n, expected):
67
+ assert sabctools.crc32_xpown(n) == expected
68
+
69
+
70
+ @pytest.mark.parametrize(
71
+ "n,expected",
72
+ [
73
+ (0, 2147483648),
74
+ (1, 8388608),
75
+ (4294967295, 2147483648),
76
+ (4294967296, 8388608), # 1
77
+ ],
78
+ )
79
+ def test_crc32_xpow8n_expected(n, expected):
80
+ assert sabctools.crc32_xpow8n(n) == expected
@@ -0,0 +1,115 @@
1
+ import sys
2
+ import pytest
3
+ import glob
4
+ from tests.testsupport import *
5
+
6
+
7
+ def test_regular():
8
+ data_plain = read_plain_yenc_file("test_regular.yenc")
9
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
10
+ data_plain = read_plain_yenc_file("test_regular_2.yenc")
11
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
12
+
13
+
14
+ def test_bytes_compat():
15
+ data_plain = read_plain_yenc_file("test_regular.yenc")
16
+ assert python_yenc(data_plain) == sabctools.yenc_decode(memoryview(bytes(data_plain)))
17
+
18
+
19
+ def test_partial():
20
+ data_plain = read_plain_yenc_file("test_partial.yenc")
21
+ decoded_data, filename, filesize, begin, size, crc_correct = sabctools_yenc_wrapper(data_plain)
22
+ assert filename == "90E2Sdvsmds0801dvsmds90E.part06.rar"
23
+ assert filesize == 49152000
24
+ assert begin == 15360000
25
+ assert size == 384000
26
+ assert crc_correct is None
27
+ assert len(decoded_data) == 549
28
+
29
+
30
+ def test_special_chars():
31
+ data_plain = read_plain_yenc_file("test_special_chars.yenc")
32
+ # We only compare the data and the filename
33
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
34
+
35
+ data_plain = read_plain_yenc_file("test_special_utf8_chars.yenc")
36
+ # We only compare the data and the filename
37
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
38
+
39
+
40
+ def test_bad_crc():
41
+ data_plain = read_plain_yenc_file("test_bad_crc.yenc")
42
+ # We only compare the data and the filename
43
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
44
+
45
+
46
+ def test_bad_crc_end():
47
+ data_plain = read_plain_yenc_file("test_bad_crc_end.yenc")
48
+ with pytest.raises(ValueError) as excinfo:
49
+ sabctools_yenc_wrapper(data_plain)
50
+ assert "Invalid CRC in footer" in str(excinfo.value)
51
+
52
+
53
+ def test_no_filename():
54
+ data_plain = read_plain_yenc_file("test_no_name.yenc")
55
+ with pytest.raises(ValueError) as excinfo:
56
+ sabctools_yenc_wrapper(data_plain)
57
+ assert "Could not find yEnc filename" in str(excinfo.value)
58
+
59
+
60
+ def test_padded_crc():
61
+ data_plain = read_plain_yenc_file("test_padded_crc.yenc")
62
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
63
+
64
+
65
+ def test_end_after_filename():
66
+ data_plain = read_plain_yenc_file("test_end_after_filename.yenc")
67
+ with pytest.raises(ValueError):
68
+ sabctools_yenc_wrapper(data_plain)
69
+
70
+
71
+ def test_empty():
72
+ with pytest.raises(ValueError) as excinfo:
73
+ sabctools.yenc_decode(memoryview(bytearray(b"")))
74
+ assert "Invalid data length" in str(excinfo.value)
75
+
76
+
77
+ def test_ref_counts():
78
+ """Note that sys.getrefcount itself adds another reference!"""
79
+ # Test regular case
80
+ data_plain = read_plain_yenc_file("test_regular.yenc")
81
+ data_out, filename, filesize, begin, end, crc_correct = sabctools_yenc_wrapper(data_plain)
82
+
83
+ assert sys.getrefcount(data_plain) == 2
84
+ assert sys.getrefcount(data_out) == 2
85
+ assert sys.getrefcount(filename) == 2
86
+ assert sys.getrefcount(begin) == 2
87
+ assert sys.getrefcount(end) == 2
88
+ assert sys.getrefcount(crc_correct) == 2
89
+
90
+ # Test simple error case
91
+ fake_inp = memoryview(bytearray(b"1234"))
92
+ assert sys.getrefcount(fake_inp) == 2
93
+ with pytest.raises(ValueError):
94
+ sabctools.yenc_decode(fake_inp)
95
+ assert sys.getrefcount(fake_inp) == 2
96
+
97
+ # Test further processing
98
+ data_plain = read_plain_yenc_file("test_bad_crc_end.yenc")
99
+ with pytest.raises(ValueError):
100
+ sabctools_yenc_wrapper(data_plain)
101
+ assert sys.getrefcount(data_plain) == 2
102
+
103
+
104
+ def test_crc_pickles():
105
+ all_crc_fails = glob.glob("tests/yencfiles/crc_*")
106
+ for fname in all_crc_fails:
107
+ data_plain = read_pickle(fname)
108
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
109
+
110
+
111
+ def test_small_file_pickles():
112
+ all_pickles = glob.glob("tests/yencfiles/small_file*")
113
+ for fname in all_pickles:
114
+ data_plain = read_pickle(fname)
115
+ assert python_yenc(data_plain) == sabctools_yenc_wrapper(data_plain)
@@ -0,0 +1,7 @@
1
+ from tests.testsupport import *
2
+
3
+
4
+ def test_encoder():
5
+ output, crc = sabctools.yenc_encode(b"Hello world!")
6
+ assert output == b"r\x8f\x96\x96\x99J\xa1\x99\x9c\x96\x8eK"
7
+ assert crc == 0x1B851995
@@ -0,0 +1,45 @@
1
+ import os
2
+ import subprocess
3
+ import sys
4
+ import tempfile
5
+ import pytest
6
+ from typing import IO
7
+
8
+ from tests.testsupport import *
9
+
10
+
11
+ def test_sparse():
12
+ file = tempfile.NamedTemporaryFile(delete=False)
13
+ try:
14
+ sabctools.sparse(file, 100)
15
+ assert os.path.getsize(file.name) == 100
16
+ assert is_sparse(file) is True
17
+ finally:
18
+ file.close()
19
+ os.unlink(file.name)
20
+
21
+ @pytest.mark.parametrize(
22
+ "length,position",
23
+ [
24
+ (1024, 0),
25
+ (1024, 512),
26
+ (1024, 4096),
27
+ ],
28
+ )
29
+ def test_sparse_position_expected(length, position):
30
+ with tempfile.TemporaryFile() as file:
31
+ file.seek(position)
32
+ sabctools.sparse(file, length)
33
+ assert file.tell() == position
34
+
35
+ def is_sparse(file: IO) -> bool:
36
+ """Is the file sparse?
37
+ On Windows this closes the file"""
38
+ if sys.platform == "win32":
39
+ file.close()
40
+ return b"This file is set as sparse" in subprocess.run(
41
+ ["fsutil", "sparse", "queryflag", file.name],
42
+ capture_output=True
43
+ ).stdout
44
+
45
+ return os.stat(file.name).st_blocks * 512 < os.path.getsize(file.name)