def test_download_force_flag(tmp_path, mocked_responses, capsys, caplog, extra): mocked_responses.add(responses.GET, DEFAULT_LISTFILE_URL, body='12345;DEFAULT_LISTFILE_URL DOWNLOAD', status=200, content_type='application/json') listfile = tmp_path / "listfile.csv" wowdump.set_default_listfile(listfile) # If it doesn't exist and we've said we don't want to download it, # make sure we don't download it assert not listfile.exists(), "our fresh tmpdir already has a listfile?!" ret = wowdump.main([ # "--listfile", str(listfile), "--no-download-listfile", ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" # assert ("csvcache", logging.WARNING, # str(listfile) + " does not exist, not resolving fileids") in caplog.record_tuples captured = capsys.readouterr() assert "WARNING: listfile does not exist, fdid name resolution disabled" in captured.err assert not listfile.exists(), "downloaded listfile when we shouldn't have" # If it doesn't exist otherwise, we should try to download it ret = wowdump.main([ # "--listfile", str(listfile), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "NOTICE: downloading new listfile" in captured.err assert listfile.read_text() == "12345;DEFAULT_LISTFILE_URL DOWNLOAD" # it exists now, make sure we don't try to download it again # If it doesn't exist otherwise, we should try to download it ret = wowdump.main([ # "--listfile", str(listfile), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "WARNING: listfile does not exist" not in captured.err assert "NOTICE: downloading new listfile" not in captured.err # it exists, but make sure we _do_ try to download it if we # explicitly request it ret = wowdump.main([ # "--listfile", str(listfile), "--download-listfile", ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "NOTICE: downloading new listfile" in captured.err
def test_filter_keep_multi(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--filter", "/model/version", "--filter", "/model/collision_sphere_radius", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # basically identical to the previous test # make sure what we want is there assert "/model/version =" in captured.out assert "/model/collision_sphere_radius" in captured.out # make sure other things aren't assert "/model/textures" not in captured.out # make sure our elison messages aren't (sloppilly) (FIXME: do better?) assert "elided" not in captured.out # check total lines assert len(captured.out.rstrip("\n").split("\n")) == 2
def test_simplify(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--simplify", # also the default os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # make sure we got our simplifier output as expected assert "/model/bounding_box/max = xyz(8.763622, 2.173703, 9.998041)" in captured.out
def test_simplify_nosimplify(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--no-simplify", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # FIXME: can/should we check for -any- simplifier in the output? assert " = xyz(" not in captured.out
def test_unneeded_nohide(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--no-simplify", "--no-hide-unneeded", # the default os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "/model/num_bone_lookup" in captured.out
def test_contenthash(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--no-simplify", # don't do more work than needed os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # contenthash should always be the first line, and should always be there assert captured.out.split( "\n")[0] == "/contenthash = d1b1a625d1396a83b907319265346580"
def t_bulk(request, extra): fn = request.param # type: Path if fn == "no_bulk_tests": return ret = wowdump.main([ "--no-resolve", "-o", "scratch.txt", str(fn), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" return fn
def test_download_500(tmp_path, mocked_responses, capsys, extra): mocked_responses.add(responses.GET, DEFAULT_LISTFILE_URL, body='DEFAULT_LISTFILE_URL ERROR', status=500) listfile = tmp_path / "listfile.csv" ret = wowdump.main([ "--listfile", str(listfile), "--download-listfile", ]) assert ret == 69, f"wowdump exited with improper exit code (should be 69 (os.EX_UNAVAILABLE)), was {ret}" captured = capsys.readouterr() assert "NOTICE: downloading new listfile" in captured.err assert "ERROR: couldn't download listfile: 500 Internal Server Error" in captured.err
def test_resolve(request, capsys, extra): ret = wowdump.main([ "--resolve", "--listfile", os.path.join(request.config.rootdir, DATADIR, "listfile_minimal.csv"), os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # Make sure we actually got fdid resolution assert "skin_file_data_ids/0 = 494151 # spells/levelup/levelup00.skin" in captured.out assert "file_data_ids/0 = 167220 # spells/yellow_glow_dim2.blp" in captured.out # Make sure we correctly get 'unresolved' on things that shouldn't exist assert "file_data_ids/2 = 166153 # unresolved" in captured.out
def test_download_200(tmp_path, mocked_responses, capsys, extra): mocked_responses.add(responses.GET, DEFAULT_LISTFILE_URL, body='12345;DEFAULT_LISTFILE_URL DOWNLOAD', status=200, content_type='application/json') listfile = tmp_path / "listfile.csv" ret = wowdump.main([ "--listfile", str(listfile), "--download-listfile", ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "NOTICE: downloading new listfile" in captured.err assert listfile.read_text() == "12345;DEFAULT_LISTFILE_URL DOWNLOAD"
def test_resolve_missing_listfile(request, capsys, caplog, extra): ret = wowdump.main([ "--resolve", "--listfile", "/this/does/not/exist", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # verify we get our warning for the missing listfile assert ("csvcache", logging.WARNING, str(Path("/this/does/not/exist")) + " does not exist, not resolving fileids") in caplog.record_tuples # make sure we're correctly; showing things as "unresolved" # FIXME: Do we want 'unresolved', or nothing? assert "skin_file_data_ids/0 = 494151 # unresolved" in captured.out
def test_geometry_arraylimit_zero(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--geometry", "--arraylimit", "0", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # Make sure we don't get the geometry elision message (might be overkill) assert "geometry data elided, use --geometry to include" not in captured.out # verify we get all the geometry data (levelup.m2 has 100 verts, 0 - 99) assert "/model/vertices/99" in captured.out # verify we don't get an elision message at all assert "/model/vertices/..." not in captured.out
def test_filter_discard(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--filter", "!/model/vertices", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # make sure what we don't want isn't there # this will also fail if the geometry elision text for this is there assert "/model/vertices" not in captured.out # and what we don't don't want is there assert "/model/textures" in captured.out # our elided text should still be there assert "elided" in captured.out
def t_reference_output(request, outputdir): test = request.param # type: t outputsubdir = os.path.join(outputdir, test.type) if not os.path.exists(outputsubdir): os.makedirs(outputsubdir) inpath = os.path.join(request.config.rootdir, DATADIR, test.infile) outpath = os.path.join(outputsubdir, f"{test.infile}.{test.ext}") ret = wowdump.main([ "--no-resolve", "-o", outpath, ] + test.dumpflags + [ inpath, ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" return test
def test_resolve_noresolve(request, capsys, caplog, extra): ret = wowdump.main([ "--no-resolve", "--listfile", "/this/does/not/exist", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # verify we don't get an error on opening listfile (because we shouldn't # be trying to open it at all) assert "does not exist, not resolving fileids" not in caplog.text # nothing should show 'unresolved' if resolution isn't enabled assert " # unresolved" not in captured.out # make sure we didn't somehow resolve anything, too assert " # spells/yellow_glow_dim2.blp" not in captured.out
def test_download_alternate_url(tmp_path, mocked_responses, capsys, extra): alternate_url = "http://example.com/listfile.csv" mocked_responses.add(responses.GET, alternate_url, body='12345;ALTERNATE_URL DOWNLOAD', status=200) listfile = tmp_path / "listfile.csv" ret = wowdump.main([ "--listfile", str(listfile), "--listfile-url", alternate_url, "--download-listfile", ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() assert "NOTICE: downloading new listfile" in captured.err assert listfile.read_text() == "12345;ALTERNATE_URL DOWNLOAD"
def test_filter_keep_discard(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--filter", "/model/texture_weights/0", "--filter", "!/model/texture_weights", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # Make sure we got the part we wanted to keep assert "/model/texture_weights/0" in captured.out # and that we don't have the part we want filtered assert "/model/texture_weights/1" not in captured.out # and that other stuff still exists assert "/model/textures" in captured.out
def test_geometry_arraylimit(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--geometry", "--arraylimit", "50", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # Make sure we don't get the elision message assert "geometry data elided, use --geometry to include" not in captured.out # verify we get geometry data up to our limit assert "/model/vertices/49" in captured.out # verify we don't get more than our limit assert "/model/vertices/50" not in captured.out # verify we get the elision message assert "/model/vertices/... = [50 elided of 100 total]" in captured.out
def test_arraylimit_all(request, capsys, extra): ret = wowdump.main([ "--no-resolve", "--elide-all", "--arraylimit", "25", os.path.join(request.config.rootdir, DATADIR, input_model), ]) assert ret == 0, f"wowdump exited with non-zero exit code ({ret})" captured = capsys.readouterr() # FIXME: should bone_lookup be a geometry thing and normally elided? # Check to make sure non-geometry elision happens # bone_lookup 24 should exist assert "/model/bone_lookup/24 =" in captured.out # bone_lookup 25 should not assert "/model/bone_lookup/25 =" not in captured.out # make sure we get our elision message assert "/model/bone_lookup/... = [39 elided of 64 total]" in captured.out