diff --git a/tests/sabnews.py b/tests/sabnews.py index 8aa3912..cfc2e45 100644 --- a/tests/sabnews.py +++ b/tests/sabnews.py @@ -25,7 +25,7 @@ Run sabnews.py -h for parameters! import os import re import time -import zlib +import sabyenc3 import argparse import asyncio import logging @@ -109,31 +109,12 @@ class NewsServerProtocol(asyncio.Protocol): inp_file.seek(start) inp_buffer = inp_file.read(size) - # Calculate CRC of input - crc = zlib.crc32(inp_buffer) & 0xFFFFFFFF - - # yEnc-encoder - line_size = 0 - crc = 0 - for ch in inp_buffer: - # Write special chars - out_ch = (ch + 42) % 256 - if out_ch in YENC_ESCAPE: - self.transport.write(b"=") - line_size += 1 - out_ch = (out_ch + 64) % 256 - - # Write regular chars - self.transport.write(bytes([out_ch])) - line_size += 1 - - # Check line-size - if line_size and not line_size >= 128: - self.transport.write(b"\r\n") - line_size = 0 + # Encode data + output_string, crc = sabyenc3.encode(inp_buffer) + self.transport.write(output_string) # Write footer - self.transport.write(b"=yend size=%d part=%d pcrc32=%08x\r\n" % (size, part, crc)) + self.transport.write(b"\r\n=yend size=%d part=%d pcrc32=%08x\r\n" % (size, part, crc)) self.transport.write(b".\r\n") def close_connection(self): @@ -186,7 +167,7 @@ def create_nzb(nzb_file=None, nzb_dir=None): for fl in files_for_nzb: nzb.write( - '\n' % (current_time, os.path.basename(fl)) + '\n' % (current_time, os.path.basename(fl)) ) nzb.write("alt.binaries.test\n") nzb.write("\n") diff --git a/tests/test_functional_downloads.py b/tests/test_functional_downloads.py index 8e4805b..91665c6 100644 --- a/tests/test_functional_downloads.py +++ b/tests/test_functional_downloads.py @@ -29,7 +29,7 @@ from tests.testhelper import * class SABnzbdDownloadFlow(SABnzbdBaseTest): def is_server_configured(self): """ Check if the wizard was already performed. - If not: run the wizard and start sabnews! + If not: run the wizard! """ with open(os.path.join(SAB_CACHE_DIR, "sabnzbd.ini"), "r") as config_file: if SAB_NEWSSERVER_HOST not in config_file.read(): @@ -93,7 +93,7 @@ class SABnzbdDownloadFlow(SABnzbdBaseTest): self.open_page("http://%s:%s/sabnzbd/" % (SAB_HOST, SAB_PORT)) # We wait for 30 seconds to let it complete - for _ in range(120): + for _ in range(30): try: # Locate resulting row result_row = self.driver.find_element_by_xpath( @@ -120,7 +120,7 @@ class SABnzbdDownloadFlow(SABnzbdBaseTest): self.is_server_configured() self.add_test_nzb("basic_rar5", "testfile.bin") - @pytest.mark.skip(reason="Fails due to problem with sabnews") + @pytest.mark.skip(reason="Fails due to problem with SABNews") def test_download_unicode_rar(self): self.is_server_configured() self.add_test_nzb("http://sabnzbd.org/tests/unicode_rar.nzb", "\u4f60\u597d\u4e16\u754c.bin") diff --git a/tests/testhelper.py b/tests/testhelper.py index 590999c..b93a628 100644 --- a/tests/testhelper.py +++ b/tests/testhelper.py @@ -119,12 +119,12 @@ def get_api_result(mode, host=SAB_HOST, port=SAB_PORT, extra_arguments={}): def start_sabnews(): - """ Start sabnews and forget about it """ + """ Start SABNews and forget about it """ return subprocess.Popen([sys.executable, "%s/sabnews.py" % SAB_BASE_DIR]) def create_nzb(nzb_dir): - """ Create NZB from directory using sabnews """ + """ Create NZB from directory using SABNews """ nzb_dir_full = os.path.join(SAB_BASE_DIR, "data", nzb_dir) return tests.sabnews.create_nzb(nzb_dir=nzb_dir_full) @@ -162,9 +162,10 @@ class SABnzbdBaseTest(unittest.TestCase): # If something else fails, this can cause very non-informative long tracebacks pass - # Kill sabnews + # Kill SABNews try: cls.sabnews.kill() + cls.sabnews.communicate() except: pass