Example #1
0
def test_mediainfo_scraper_mov(filename, result_dict, mimetype,
                               evaluate_scraper):
    """
    Test Quicktime and DV scraping with Mediainfo.

    :filename: Test file name
    :result_dict: Result dict containing the test purpose, parts of
                  expected results of stdout and stderr, and expected
                  streams
    :mimetype: File MIME type
    """
    correct = parse_results(filename, mimetype, result_dict, False)
    scraper = MediainfoScraper(filename=correct.filename, mimetype=mimetype)
    scraper.scrape_file()

    if filename == "valid__h264_aac_no_ftyp_atom.mov":
        correct.streams[0]["codec_name"] = "QuickTime"
    if ".dv" in filename:
        correct.streams[0].pop("stream_type", None)

    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #2
0
def test_mediainfo_scraper_mkv(filename, result_dict, evaluate_scraper):
    """
    Test Matroska scraping with Mediainfo.

    :filename: Test file name
    :result_dict: Result dict containing the test purpose, parts of
                  expected results of stdout and stderr, and expected
                  streams
    """
    mimetype = "video/x-matroska"
    correct = parse_results(filename, mimetype, result_dict, False)
    scraper = MediainfoScraper(filename=correct.filename, mimetype=mimetype)
    scraper.scrape_file()
    if "empty" in filename:
        correct.version = None
        correct.streams[0]["version"] = None
        correct.streams[0]["stream_type"] = None

    if "invalid" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #3
0
def test_mediainfo_scraper_wav(filename, result_dict, evaluate_scraper):
    """
    Test WAV scraping with Mediainfo.

    :filename: Test file name
    :result_dict: Result dict containing the test purpose, parts of
                  expected results of stdout and stderr, and expected
                  streams
    """
    mimetype = "audio/x-wav"
    correct = parse_results(filename, mimetype, result_dict, False)
    if "2" in filename:
        correct.streams[0]["version"] = "2"
    else:
        correct.streams[0]["version"] = UNAP

    scraper = MediainfoScraper(filename=correct.filename, mimetype=mimetype)
    scraper.scrape_file()

    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #4
0
def run_filetype_test(filename, result_dict, filetype, evaluate_scraper):
    """
    Runs scraper result evaluation for a scraper with forced MIME type/version

    :filename: Name of the file, not containing the tests/data/mime_type/ part
    :result_dict: Result dict to be given to Correct
    :filetype: A dict containing the forced, expected and real file types under
               the following keys:
                * given_mimetype: the forced MIME type
                * given_version: the forced version
                * expected_mimetype: the expected resulting MIME type
                * expected_version: the expected resulting version
                * correct_mimetype: the real MIME type of the file
    """
    correct = force_correct_filetype(filename, result_dict, filetype)

    if filetype["given_mimetype"]:
        mimetype_guess = filetype["given_mimetype"]
    else:
        mimetype_guess = filetype["correct_mimetype"]
    params = {
        "mimetype": filetype["given_mimetype"],
        "version": filetype["given_version"],
        "mimetype_guess": mimetype_guess
    }
    scraper = MediainfoScraper(correct.filename, True, params)
    scraper.scrape_file()

    evaluate_scraper(scraper, correct)
Example #5
0
def test_mediainfo_scraper_avi(filename, result_dict):
    """
    Test AVI scraping with Mediainfo.

    Both Mediainfo and FFMpeg cannot be used for metadata scraping, and FFMpeg
    meets our needs better with AVI, so MediainfoScraper should just return one
    stream full of unavs to be overwritten by results from FFMpeg.
    """
    mimetype = "video/avi"
    correct = parse_results(filename, mimetype, result_dict, True)

    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()

    assert partial_message_included(correct.stdout_part, scraper.messages())
    assert partial_message_included(correct.stderr_part, scraper.errors())
    if "invalid" in filename:
        assert not scraper.streams
    else:
        assert len(scraper.streams) == 1
        for method in scraper.streams[0].iterate_metadata_methods():
            if method.__name__ == "index":
                assert method() == 0
            else:
                assert method() == "(:unav)"
Example #6
0
def test_no_wellformed():
    """Test scraper without well-formed check."""
    scraper = MediainfoScraper("tests/data/audio_x-wav/valid__wav.wav",
                               False,
                               params={"mimetype_guess": "audio/x-wav"})
    scraper.scrape_file()
    assert not partial_message_included("Skipping scraper", scraper.messages())
    assert scraper.well_formed is None
Example #7
0
def test_no_mime_given():
    """Test that an error is recorded when no MIME type is given."""
    scraper = MediainfoScraper("tests/data/audio_mpeg/valid_1.mp3", True, {})
    with pytest.raises(AttributeError) as error:
        scraper.scrape_file()
    assert ("not given a parameter dict containing key 'mimetype_guess'"
            in six.text_type(error.value))
    assert ("not given a parameter dict containing key 'mimetype_guess'"
            in str(error.value))
    assert not scraper.well_formed
    assert not scraper.streams
Example #8
0
def test_mediainfo_scraper_mpeg(filename, result_dict, evaluate_scraper):
    """Test MPEG scraping with MediainfoScraper."""
    mimetype = "video/mpeg"
    correct = parse_results(filename, mimetype, result_dict, True)
    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()
    del correct.streams[0]["stream_type"]
    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #9
0
def test_mediainfo_scraper_mpegts(filename, result_dict, evaluate_scraper):
    """Test MPEG Transport Stream scraping with MediainfoScraper."""
    mimetype = "video/MP2T"
    correct = parse_results(filename, mimetype, result_dict, True)
    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()
    for stream in correct.streams.values():
        if stream["mimetype"] == "video/MP2T":
            stream["version"] = "(:unav)"
    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #10
0
def test_mediainfo_scraper_mov(filename, result_dict, mimetype,
                               evaluate_scraper):
    """Test Quicktime and DV scraping with Mediainfo."""
    correct = parse_results(filename, mimetype, result_dict, True)
    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()

    if ".dv" in filename:
        correct.streams[0].pop("stream_type", None)

    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #11
0
def test_mediainfo_scraper_wav(filename, result_dict, evaluate_scraper):
    """Test WAV scraping with Mediainfo."""
    mimetype = "audio/x-wav"
    correct = parse_results(filename, mimetype, result_dict, True)
    if "2" in filename:
        correct.streams[0]["version"] = "2"

    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()

    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #12
0
def test_mediainfo_scraper_avi(evaluate_scraper):
    """Test AVI scraping with MediainfoScraper."""
    filename = "valid__mpeg2_mp3.avi"
    mimetype = "video/avi"
    result_dict = {
        "purpose": "Test valid AVI.",
        "stdout_part": "file was analyzed successfully",
        "stderr_part": "",
        "streams": {
            0: AVI_CONTAINER.copy(),
            1: AVI_VIDEO.copy(),
            2: AVI_AUDIO.copy()
        }
    }

    correct = parse_results(filename, mimetype, result_dict, False)
    scraper = MediainfoScraper(filename=correct.filename, mimetype=mimetype)
    scraper.scrape_file()

    evaluate_scraper(scraper, correct)
Example #13
0
def test_mediainfo_scraper_mpeg(filename, result_dict, evaluate_scraper):
    """
    Test MPEG scraping with MediainfoScraper.

    :filename: Test file name
    :result_dict: Result dict containing the test purpose, parts of
                  expected results of stdout and stderr, and expected
                  streams
    """
    mimetype = "video/mpeg"
    correct = parse_results(filename, mimetype, result_dict, False)
    scraper = MediainfoScraper(filename=correct.filename, mimetype=mimetype)
    scraper.scrape_file()
    if "empty" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)
Example #14
0
def test_mediainfo_scraper_mkv(filename, result_dict, evaluate_scraper):
    """Test Matroska scraping with Mediainfo."""
    mimetype = "video/x-matroska"
    correct = parse_results(filename, mimetype, result_dict, True)
    scraper = MediainfoScraper(correct.filename,
                               True,
                               params={"mimetype_guess": mimetype})
    scraper.scrape_file()
    if "empty" in filename:
        correct.version = None
        correct.streams[0]["version"] = None
        correct.streams[0]["stream_type"] = None

    if "invalid" in filename:
        assert partial_message_included(correct.stdout_part,
                                        scraper.messages())
        assert partial_message_included(correct.stderr_part, scraper.errors())
        assert not scraper.streams
    else:
        evaluate_scraper(scraper, correct)