def short_frame_middle(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() temp.add_valid_frames(10) junk_start = temp.get_size() header = temp.last_header temp.add_header(header) temp.add_bytes(9) #less than a full frame frame_restart = temp.get_size() temp.add_valid_frames(10, header) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(20, len(mfile.frames), "Found more or less frames") self.assertEqual(1, len(mfile.other), "Found data where there was none") self.assertEqual(0, mfile.frames[0][1], "Found first frame at wrong position") self.assertEqual(frame_restart, mfile.frames[10][1], "Didn't detect next full frame") self.assertEqual( junk_start, mfile.other[0].position, "Junk not found in correct location (junk is valid frame cut short)" ) self.assertEqual( 13, len(mfile.other[0]), "Junk found had wrong length (junk i svalid frame cut short)")
def junk_all_three(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() junk_amount1 = 2007 junk_amount2 = 5213 junk_amount3 = 128 temp.add_bytes(junk_amount1) temp.add_valid_frame() temp.add_valid_frames(9, temp.last_header) junk_start = temp.get_size() temp.add_bytes(junk_amount2) temp.add_valid_frames(10, temp.last_header) junk_start2 = temp.get_size() temp.add_bytes(junk_amount3) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(20, len(mfile.frames), "Found wrong number of frames") self.assertEqual(3, len(mfile.other), "Found data where there was none") self.assertEqual(junk_amount1, mfile.frames[0][1], "Found frame at wrong position") self.assertEqual(0, mfile.other[0].position, "Junk found at wrong location") self.assertEqual(junk_start, mfile.other[1].position, "Junk found at wrong location") self.assertEqual(junk_start2, mfile.other[2].position, "Junk found at wrong location") self.assertEqual(junk_amount1, len(mfile.other[0]), "Junk found had wrong length") self.assertEqual(junk_amount2, len(mfile.other[1]), "Junk found had wrong length") self.assertEqual(junk_amount3, len(mfile.other[2]), "Junk found had wrong length")
def basic_id3_test(self): """implement of above""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() temp.add_id3v1_tag("a title","an artist", "an album") mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(1, len(mfile.other),"More than one tag found") self.assertEqual(id3.ID3v1x, type(mfile.other[0]), "failed to identify v1 tag") self.assertEqual(0, mfile.other[0].subversion, "Identified wrong subversion of tag") self.assertEqual(0, mfile.other[0].position, "failed to identify correct starting location")
def many_frames(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() temp.add_valid_frames(100) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(100, len(mfile.frames), "Found more or less than one frame") self.assertEqual(0, len(mfile.other), "Found data where there was none") self.assertEqual(0, mfile.frames[0][1], "Found frame at wrong position")
def multiple_junk(self): """implements the above""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() temp.add_bytes(200) temp.add_valid_frames(5) tagstart = temp.get_size() temp.add_id3v1_tag("a title","an artist", "an album",track=5) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(2, len(mfile.other),"More than one tag found") tag = mfile.other[0] self.assertEqual(id3.ID3v1x, type(tag), "failed to identify v1 tag") self.assertEqual(1, tag.subversion, "Identified wrong subversion of tag") self.assertEqual(tagstart, tag.position, "failed to idenitfy correct starting location")
def only_junk(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 2 #only one frame in sample file temp = SampleMP3File() junk_amount = 16384 temp.add_bytes(junk_amount) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(0, len(mfile.frames), "Found more or less than one frame") self.assertEqual(1, len(mfile.other), "Found data where there was none") self.assertEqual(0, mfile.other[0].position, "Junk found at wrong location") self.assertEqual(junk_amount, len(mfile.other[0]), "Junk found had wrong length")
def identify_frame_after_false_seek(self): """Implimentation of above""" config.OPTS.consecutive_frames_to_id = 3 temp = SampleMP3File() temp.add_char(255) temp.add_valid_frames(5) junkstart = temp.get_size() temp.add_char(255) temp.add_char(255) framestart = temp.get_size() temp.add_valid_frames(5) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(1, mfile.frames[0][1], "Didn't skip false seek byte") self.assertEqual(0, mfile.other[0].position, "junk #1 found in wrong location") self.assertEqual(junkstart, mfile.other[1].position, "junk #2 found in wrong location") self.assertEqual(2, len(mfile.other[1]), "junk was wrong length") self.assertEqual(framestart, mfile.frames[5][1], "Didn't skip 2 byte false seek tag")
def short_frame_end(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 2 temp = SampleMP3File() temp.add_valid_frames(3) junk_start = temp.get_size() header = temp.last_header temp.add_header(header) temp.add_bytes(9) #less than a full frame mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(3, len(mfile.frames), "Found more or less than one frame") self.assertEqual(1, len(mfile.other), "Found data where there was none") self.assertEqual(0, mfile.frames[0][1], "Found frame at wrong position") self.assertEqual(junk_start, mfile.other[0].position, "Junk found at wrong location") self.assertEqual(13, len(mfile.other[0]), "Junk found had wrong length")
def junk_middle(self): """implimentation of above.""" config.OPTS.consecutive_frames_to_id = 3 #only one frame in sample file temp = SampleMP3File() junk_amount = 2007 temp.add_valid_frame() temp.add_valid_frames(9, temp.last_header) junk_start = temp.get_size() temp.add_bytes(junk_amount) temp.add_valid_frames(10, temp.last_header) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(20, len(mfile.frames), "Found wrong number of frames") self.assertEqual(1, len(mfile.other), "Found data where there was none") self.assertEqual(0, mfile.frames[0][1], "Found frame at wrong position") self.assertEqual(junk_start, mfile.other[0].position, "Junk found at wrong location") self.assertEqual(junk_amount, len(mfile.other[0]), "Junk found had wrong length")
def test_short_19_python_extended_lockon_test(self): """Because the python code uses two different methods to lock on - one to skip large empty chunks and one to quickly parse frequent hits, we must test both by exceeding the limit of the first.""" config.OPTS.consecutive_frames_to_id = 3 config.OPTS.use_numpy = False temp = SampleMP3File() temp.add_valid_frames(5) junkstart = temp.get_size() for _ in range(mp3file._MAX_INDEX_METHOD_SEARCHES * 2): temp.add_bytes(11) temp.add_char(255) nextframe = temp.get_size() temp.add_valid_frames(5) mfile = mp3file.MP3File(temp.get_file()) mfile.scan_file() self.assertEqual(nextframe, mfile.frames[5][1], "unable to find frame with secondary lockon method") self.assertEqual(junkstart, mfile.other[0].position, "junk foun in wrong location") self.assertEqual(24 * mp3file._MAX_INDEX_METHOD_SEARCHES, len(mfile.other[0]), "junk found was wrong size")