test_makemkv.py (2903B)
1 import pytest 2 3 from simplefe import makemkv 4 5 SAMPLE_OUTPUT = """\ 6 MSG:1005,0,1,"MakeMKV v1.18.4 linux(x64-release) started","%1","1.18.4" 7 DRV:0,2,999,12,"BD-RE PIONEER BD-RW BDR-XD08 1.02","ARRIVAL_2016_UHD","/dev/sr0" 8 CINFO:1,6209,"Blu-ray disc" 9 CINFO:2,0,"ARRIVAL_2016_UHD" 10 CINFO:28,0,"1" 11 TCOUNT:2 12 TINFO:0,2,0,"Title 0" 13 TINFO:0,9,0,"0:03:12" 14 TINFO:0,27,0,"title00.mkv" 15 TINFO:1,2,0,"Title 1" 16 TINFO:1,9,0,"1:56:09" 17 TINFO:1,27,0,"title01.mkv" 18 """ 19 20 21 def test_guess_movie_name_strips_junk_words_and_underscores(): 22 assert makemkv.guess_movie_name("ARRIVAL_2016_UHD") == "Arrival 2016" 23 24 25 def test_guess_movie_name_strips_resolution_tokens(): 26 assert makemkv.guess_movie_name("MOVIE_1920x1080_BD") == "Movie" 27 28 29 def test_guess_movie_name_empty_input(): 30 assert makemkv.guess_movie_name("") == "" 31 32 33 def test_parse_disc_info_picks_longest_title_as_main(): 34 info = makemkv.parse_disc_info(SAMPLE_OUTPUT) 35 assert info.raw_id == "ARRIVAL_2016_UHD" 36 assert info.guessed_name == "Arrival 2016" 37 assert info.main_title == 1 38 39 40 def test_parse_disc_info_handles_empty_output(): 41 info = makemkv.parse_disc_info("") 42 assert info.raw_id == "" 43 assert info.guessed_name == "" 44 assert info.main_title == 0 45 46 47 def test_find_existing_rip_returns_none_when_not_present(tmp_path): 48 db_path = tmp_path / "rip.db" 49 assert makemkv.find_existing_rip(str(db_path), "SOME_DISC_ID") is None 50 51 52 def test_find_existing_rip_with_empty_raw_id_returns_none(tmp_path): 53 db_path = tmp_path / "rip.db" 54 assert makemkv.find_existing_rip(str(db_path), "") is None 55 56 57 def test_record_and_find_existing_rip(tmp_path): 58 db_path = tmp_path / "rip.db" 59 makemkv.record_rip( 60 str(db_path), "SOME_DISC_ID", "Arrival 2016", "/mnt/Movies/Arrival 2016.mkv", 123456 61 ) 62 existing = makemkv.find_existing_rip(str(db_path), "SOME_DISC_ID") 63 assert existing["title"] == "Arrival 2016" 64 assert existing["output_file"] == "/mnt/Movies/Arrival 2016.mkv" 65 assert existing["ripped_at"] 66 67 68 def test_rip_title_finds_newly_created_file(tmp_path, monkeypatch): 69 def fake_run(cmd, check=True): 70 (tmp_path / "title01.mkv").write_bytes(b"fake mkv data") 71 72 monkeypatch.setattr(makemkv.subprocess, "run", fake_run) 73 result = makemkv.rip_title(0, 1, tmp_path) 74 assert result == tmp_path / "title01.mkv" 75 76 77 def test_rip_title_ignores_pre_existing_files(tmp_path, monkeypatch): 78 (tmp_path / "old.mkv").write_bytes(b"old") 79 80 def fake_run(cmd, check=True): 81 (tmp_path / "new.mkv").write_bytes(b"new") 82 83 monkeypatch.setattr(makemkv.subprocess, "run", fake_run) 84 result = makemkv.rip_title(0, 1, tmp_path) 85 assert result == tmp_path / "new.mkv" 86 87 88 def test_rip_title_raises_if_no_new_file(tmp_path, monkeypatch): 89 monkeypatch.setattr(makemkv.subprocess, "run", lambda cmd, check=True: None) 90 with pytest.raises(RuntimeError): 91 makemkv.rip_title(0, 1, tmp_path)