Files
sabnzbd/tests/test_functional_sorting.py
mnightingale ec6ba3baae Speed up tests with pytest-xdist (#3546)
* Speed up tests with pytest-xdist

* Ignore request failures when the server disappeared

* Fix tests which modify module globals

* Fix lang change leaking

* Fix transaction compilation order breaking tests

* Always load a clean config and fix related tests

* No module globals

* Fix other test classes assigning module level by making calls

* Replace from sabnzbd.cfg import so monkeypatch works

* More global poisoning

* Fix dependant tests which worksteal breaks

* More global vars

* Drop loadscope until more failures are resolved

* Due to how pytest-xdist is implemented, the -s/--capture=no option does not work

* monkeypatch db_path

* Also patch startup_done

* loadscope
2026-08-10 17:44:18 +01:00

120 lines
4.8 KiB
Python

#!/usr/bin/python3 -OO
# Copyright 2007-2026 by The SABnzbd-Team (sabnzbd.org)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
tests.test_functional_sorting - Test downloads with season sorting and sequential files
"""
import os
import pytest
import sabnzbd
import sabnzbd.config as config
from sabnzbd.constants import DEF_INI_FILE
from tests.testhelper import DownloadFlowBasics, SAB_CACHE_DIR
# Use an ini file with a valid, old style series and movie sorting configuration
# that also serves to verify conversion to the new sorter settings is performed
INI_FILE = "sabnzbd.sorting.ini"
@pytest.mark.usefixtures("run_sabnzbd")
class TestDownloadSorting(DownloadFlowBasics):
def test_sorter_settings_conversion(self):
"""Read the ini file after the sabnzbd test instance completed startup
and verify all defined sorters were converted to the new format"""
return_status, return_msg = config.read_config(os.path.join(SAB_CACHE_DIR, DEF_INI_FILE))
assert return_status
assert not return_msg
assert config.CONFIG["sorters"]
assert len(config.CONFIG["sorters"]) == 2 # The ini file only has Series and Movie sorting
@pytest.mark.parametrize(
"test_data_dir, result",
[
(
"sea_sort_s01_4k_uhd-SABnzbd",
["Sea.Sort.S01E0" + str(n) + ".iso" for n in (1, 2, 3, 5)],
), # Data files with season and episode markers, one episode number intentionally missing
(
"sea_sort_s02_4k_uhd-SABnzbd",
["Sea.Sort.S02E0" + str(n) + ".iso" for n in (4, 6, 7, 9)],
), # Data files with episode markers only, one episode number intentionally missing
],
)
def test_download_season_sorting(self, test_data_dir, result):
"""Test season pack sorting"""
self.download_nzb(os.path.join("sorting", test_data_dir), result, True)
@pytest.mark.parametrize(
"test_data_dir, result",
[
(
"Long_live_CDs_2023_576i_mono-SABnzbd",
["Movie_DVD_" + str(n) + ".iso" for n in (1, 2, 3)],
), # Data files with "CD n" sequence markers
(
"Its_all_about_parts_2023_576i_mono-SABnzbd",
["Movie_DVD_" + str(n) + ".iso" for n in (6, 7, 8)],
), # Data file with "Part n" sequence markers
],
)
def test_download_sequential(self, test_data_dir, result):
"""Test sequential file handling"""
self.download_nzb(os.path.join("sorting", test_data_dir), result, True)
@pytest.mark.parametrize(
"testcase",
[
pytest.param(
[
(
"SINGLE_sort_s23e06_480i-SABnzbd",
["Single.Sort.S23E06.mov"],
), # Single episode, no other files
(
"SINGLE_sort_s23e06_480i-SABnzbd",
["Single.Sort.S23E06.1.mov"],
), # Repeat to verify a unique filename is applied
],
id="SINGLE_sort_s23e06_480i-SABnzbd",
),
pytest.param(
[
(
"single-ep_sort_s06e66_4k_uhd-SABnzbd",
["Single-Ep.Sort.S06E66." + ext for ext in ("avi", "srt")],
), # Single episode with associated smaller file
(
"single-ep_sort_s06e66_4k_uhd-SABnzbd",
["Single-Ep.Sort.S06E66.1." + ext for ext in ("avi", "srt")],
), # Repeat to verify unique filenames are applied
],
marks=pytest.mark.xfail(
sabnzbd.MACOS or sabnzbd.WINDOWS,
reason="Unreliable on macOS and Windows",
),
id="single-ep_sort_s06e66_4k_uhd-SABnzbd",
),
],
)
def test_download_sorting_single(self, testcase):
"""Test single episode file handling"""
for test_data_dir, result in testcase:
self.download_nzb(os.path.join("sorting", test_data_dir), result, True)