File: 01_backport_basic_upstream_encoding_test.diff

package info (click to toggle)
python-sabyenc 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 37,904 kB
  • sloc: ansic: 482; python: 471; sh: 19; makefile: 5
file content (125 lines) | stat: -rw-r--r-- 4,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# backport basic test for encoding support
From 82ec606268c4f98051e59f6de4a26b4261449dc3 Mon Sep 17 00:00:00 2001
From: Safihre <safihre@sabnzbd.org>
Date: Sun, 7 Jun 2020 20:28:35 +0200
Subject: [PATCH] Add super basic test for encoder

---
 README.md                    |  3 +--
 tests/check_debug_pickles.py |  4 +---
 tests/check_pickles.py       |  4 +---
 tests/test_decoder.py        |  4 +---
 tests/test_encoder.py        |  7 +++++++
 tests/testsupport.py         | 10 ++++------
 6 files changed, 15 insertions(+), 17 deletions(-)
 create mode 100644 tests/test_encoder.py

diff --git a/README.md b/README.md
index dca5ff0..a3272b0 100644
--- a/README.md
+++ b/README.md
@@ -29,5 +29,4 @@ Testing
 For testing we use `pytest` (install via `pip install -r tests/requirements.txt`) and test can simply be executed by browsing to the `sabyenc` directory and running:
 ```
 pytest
-```
-Note that the `sabyenc3.encode` function is currently not covered by unit tests.
\ No newline at end of file
+```
\ No newline at end of file
diff --git a/tests/check_debug_pickles.py b/tests/check_debug_pickles.py
index ce5b2cb..b9c0b3d 100644
--- a/tests/check_debug_pickles.py
+++ b/tests/check_debug_pickles.py
@@ -91,7 +91,5 @@ for fname in all_crc_fails:
 
     pdb.set_trace()  # breakpoint 612b4eac //
 
-    output_buffer, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(
-        data_chunks, data_size
-    )
+    output_buffer, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(data_chunks, data_size)
     print(crc_correct)
diff --git a/tests/check_pickles.py b/tests/check_pickles.py
index 0b24e58..2cf0fc7 100644
--- a/tests/check_pickles.py
+++ b/tests/check_pickles.py
@@ -35,9 +35,7 @@ for fname in all_crc_fails:
     """
     First we check SABYenc
     """
-    output_buffer, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(
-        data_chunks, data_size
-    )
+    output_buffer, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(data_chunks, data_size)
     print("\n---- SABYenc output ----\n")
     print("Filename:", output_filename)
     print("Size:", len(output_buffer))
diff --git a/tests/test_decoder.py b/tests/test_decoder.py
index 364ea55..682bcff 100644
--- a/tests/test_decoder.py
+++ b/tests/test_decoder.py
@@ -113,9 +113,7 @@ def test_crc_pickles():
 
 def test_empty_size_pickles():
     # When article size is left empty, it should not result in segfaults!
-    data_plain, data_chunks, data_bytes = read_pickle(
-        "tests/yencfiles/emptysize_67caae212"
-    )
+    data_plain, data_chunks, data_bytes = read_pickle("tests/yencfiles/emptysize_67caae212")
     decoded_data, filename, crc_correct = sabyenc3_wrapper(data_chunks, 0)
     assert filename == "Jake.and.the.Never.Land.Pirates.S02E38.480p.hdtv.x264.r05"
     assert crc_correct == True
diff --git a/tests/test_encoder.py b/tests/test_encoder.py
new file mode 100644
index 0000000..dda2fad
--- /dev/null
+++ b/tests/test_encoder.py
@@ -0,0 +1,7 @@
+from tests.testsupport import *
+
+
+def test_encoder():
+    output, crc = sabyenc3.encode(b"Hello world!")
+    assert output == b"r\x8f\x96\x96\x99J\xa1\x99\x9c\x96\x8eK"
+    assert crc == 3833259626
diff --git a/tests/testsupport.py b/tests/testsupport.py
index 259cd52..db3f5e6 100644
--- a/tests/testsupport.py
+++ b/tests/testsupport.py
@@ -33,7 +33,7 @@ def correct_unknown_encoding(str_or_bytes_in):
     """
     # If already string, back to bytes
     if not isinstance(str_or_bytes_in, bytes):
-        str_or_bytes_in = str_or_bytes_in.encode('utf-8', 'surrogateescape')
+        str_or_bytes_in = str_or_bytes_in.encode("utf-8", "surrogateescape")
 
     # Try simple bytes-to-string
     try:
@@ -41,10 +41,10 @@ def correct_unknown_encoding(str_or_bytes_in):
     except UnicodeDecodeError:
         try:
             # Try using 8-bit ASCII, if came from Windows
-            return str_or_bytes_in.decode('ISO-8859-1')
+            return str_or_bytes_in.decode("ISO-8859-1")
         except ValueError:
             # Last resort we use the slow chardet package
-            return str_or_bytes_in.decode(chardet.detect(str_or_bytes_in)['encoding'])
+            return str_or_bytes_in.decode(chardet.detect(str_or_bytes_in)["encoding"])
 
 
 def read_and_split(filename, chunk_size=14):
@@ -70,9 +70,7 @@ def read_pickle(filename):
 
 def sabyenc3_wrapper(data_chunks, data_bytes):
     """ CRC's are """
-    decoded_data, filename, crc_calc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(
-        data_chunks, data_bytes
-    )
+    decoded_data, filename, crc_calc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(data_chunks, data_bytes)
     return decoded_data, correct_unknown_encoding(filename), crc_correct
 
 
-- 
2.17.1