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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
#!/usr/bin/env python
"""Tests various configs load correctly
"""
from functional_runner import run_tvnamer, verify_out_data
from helpers import attr
import pytest
@attr("functional")
def test_batchconfig():
"""Test configured batch mode works
"""
conf = """
{"always_rename": true,
"select_first": true}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['Scrubs - [01x01] - My First Day.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_skip_file_on_error():
"""Test the "skip file on error" config option works
"""
conf = """
{"skip_file_on_error": true,
"always_rename": true}
"""
out_data = run_tvnamer(
with_files = ['a.fake.episode.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['a.fake.episode.s01e01.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_do_not_skip_file_on_error():
"""Test setting "skip file on error" config option to False
"""
conf = """
{"skip_file_on_error": false,
"always_rename": true}
"""
out_data = run_tvnamer(
with_files = ['a.fake.episode.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['a fake episode - [01x01].avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_skip_behaviour_warn():
"""skip_behaivour:warn should keep renaming other files
"""
conf = """
{"skip_file_on_error": false,
"batch": true,
"skip_behaviour": "warn"}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi', 'a.fake.episode.s01e01.avi', 'scrubs.s01e02.avi'],
with_config = conf,
with_input = "")
expected_files = ['a fake episode - [01x01].avi', 'Scrubs - [01x01] - My First Day.avi', 'Scrubs - [01x02] - My Mentor.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_skip_behaviour_error():
"""With skip_behaviour:error, should end process
"""
conf = """
{"skip_file_on_error": false,
"batch": true,
"skip_behaviour": "warn"}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi', 'a.fake.episode.s01e01.avi', 'scrubs.s01e02.avi'],
with_config = conf,
with_input = "")
expected_files = ['a fake episode - [01x01].avi', 'Scrubs - [01x01] - My First Day.avi', 'Scrubs - [01x02] - My Mentor.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_lowercase_names():
"""Test setting "lowercase_filename" config option
"""
conf = """
{"lowercase_filename": true,
"always_rename": true,
"select_first": true}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['scrubs - [01x01] - my first day.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_replace_with_underscore():
"""Test custom blacklist to replace " " with "_"
"""
conf = """
{"custom_filename_character_blacklist": " ",
"replace_blacklisted_characters_with": "_",
"always_rename": true,
"select_first": true}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['Scrubs_-_[01x01]_-_My_First_Day.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
@pytest.mark.xfail
def test_abs_epnmber():
"""Ensure the absolute episode number is available for custom
filenames in config
"""
conf = """
{"filename_with_episode": "%(seriesname)s - %(absoluteepisode)s%(ext)s",
"always_rename": true,
"select_first": true}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi'],
with_config = conf,
with_input = "")
expected_files = ['Scrubs - 01.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_resolve_absoloute_episode():
"""Test resolving by absolute episode number
"""
conf = """
{"always_rename": true,
"select_first": true}
"""
out_data = run_tvnamer(
with_files = ['[Bleachverse]_BLEACH_310.avi'],
with_config = conf,
with_flags=["--series-id=74796"], # Forcing series as `Bleach Kai` currently appears above Bleach in search results
with_input = "")
expected_files = ['[Bleachverse] Bleach - 310 - Ichigo\'s Resolution.avi']
verify_out_data(out_data, expected_files)
print("Checking output files are re-parsable")
out_data = run_tvnamer(
with_files = expected_files,
with_config = conf,
with_input = "")
expected_files = ['[Bleachverse] Bleach - 310 - Ichigo\'s Resolution.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_valid_extension_recursive():
"""When using valid_extensions in a custom config file, recursive search doesn't work. Github issue #36
"""
conf = """
{"always_rename": true,
"select_first": true,
"valid_extensions": ["avi","mp4","m4v","wmv","mkv","mov","srt"],
"recursive": true}
"""
out_data = run_tvnamer(
with_files = ['nested/dir/scrubs.s01e01.avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['nested/dir/Scrubs - [01x01] - My First Day.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_replace_ands():
"""Test replace "and" "&"
"""
conf = r"""
{"always_rename": true,
"select_first": true,
"input_filename_replacements": [
{"is_regex": true,
"match": "(\\Wand\\W| & )",
"replacement": " "}
]
}
"""
out_data = run_tvnamer(
with_files = ['Brothers.and.Sisters.S05E16.HDTV.XviD-LOL.avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['Brothers & Sisters - [05x16] - Home Is Where The Fort Is.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_replace_ands_in_output_also():
"""Test replace "and" "&" for search, and replace & in output filename
"""
conf = r"""
{"always_rename": true,
"select_first": true,
"input_filename_replacements": [
{"is_regex": true,
"match": "(\\Wand\\W| & )",
"replacement": " "}
],
"output_filename_replacements": [
{"is_regex": true,
"match": " & ",
"replacement": " and "}
]
}
"""
out_data = run_tvnamer(
with_files = ['Brothers.and.Sisters.S05E16.HDTV.XviD-LOL.avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['Brothers and Sisters - [05x16] - Home Is Where The Fort Is.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_force_overwrite_enabled():
"""Tests forcefully overwritting existing filenames
"""
conf = r"""
{"always_rename": true,
"select_first": true,
"overwrite_destination_on_rename": true
}
"""
out_data = run_tvnamer(
with_files = ['scrubs.s01e01.avi', 'Scrubs - [01x01] - My First Day.avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['Scrubs - [01x01] - My First Day.avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_force_overwrite_disabled():
"""Explicitly disabling forceful-overwrite
"""
conf = r"""
{"always_rename": true,
"select_first": true,
"overwrite_destination_on_rename": false
}
"""
out_data = run_tvnamer(
with_files = ['Scrubs - [01x01] - My First Day.avi', 'scrubs - [01x01].avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['Scrubs - [01x01] - My First Day.avi', 'scrubs - [01x01].avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_force_overwrite_default():
"""Forceful-overwrite should be disabled by default
"""
conf = r"""
{"always_rename": true,
"select_first": true
}
"""
out_data = run_tvnamer(
with_files = ['Scrubs - [01x01] - My First Day.avi', 'scrubs - [01x01].avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['Scrubs - [01x01] - My First Day.avi', 'scrubs - [01x01].avi']
verify_out_data(out_data, expected_files)
@attr("functional")
def test_titlecase():
"""Tests Title Case Option To Make Episodes Like This
"""
conf = r"""
{"always_rename": true,
"select_first": true,
"skip_file_on_error": false,
"titlecase_filename": true
}
"""
out_data = run_tvnamer(
with_files = ['this.is.a.fake.episode.s01e01.avi'],
with_config = conf,
with_input = "",
run_on_directory = True)
expected_files = ['This Is a Fake Episode - [01x01].avi']
verify_out_data(out_data, expected_files)
|