Repository: yt-dlp/yt-dlp
File: test/test_download.py (Python)

Code before:
                    if match_exception(err):
                        return
                    raise
                else:
                    break

            if is_playlist:
                self.assertTrue(res_dict['_type'] in ['playlist', 'multi_video'])
                self.assertTrue('entries' in res_dict)
                expect_info_dict(self, res_dict, test_case.get('info_dict', {}))

            if 'playlist_mincount' in test_case:
                assertGreaterEqual(
                    self, len(res_dict['entries']), test_case['playlist_mincount'],
                    f'Expected at least {test_case["playlist_mincount"]} entries '
                    f'in playlist {test_case["url"]}, but got only {len(res_dict["entries"])}')
            if 'playlist_count' in test_case:
                self.assertEqual(
                    len(res_dict['entries']), test_case['playlist_count'],
                    f'Expected exactly {test_case["playlist_count"]} entries '
                    f'in playlist {test_case["url"]}, but got {len(res_dict["entries"])}')
            if 'playlist_maxcount' in test_case:
                assertLessEqual(
                    self, len(res_dict['entries']), test_case['playlist_maxcount'],
                    f'Expected at most {test_case["playlist_maxcount"]} entries '
                    f'in playlist {test_case["url"]}, but got {len(res_dict["entries"])}')

            # Generalize both playlists and single videos to unified format for
            # simplicity
            if 'entries' not in res_dict:
                res_dict['entries'] = [res_dict]

            for tc_num, tc in enumerate(test_cases):
                tc_res_dict = res_dict['entries'][tc_num]
                # First, check test cases' data against extracted data alone
                expect_info_dict(self, tc_res_dict, tc.get('info_dict', {}))
                if tc_res_dict.get('_type', 'video') != 'video':
                    continue
                # Now, check downloaded file consistency
                tc_filename = get_tc_filename(tc)
                if not test_case.get('params', {}).get('skip_download', False):
                    self.assertTrue(os.path.exists(tc_filename), msg='Missing file ' + tc_filename)
                    self.assertTrue(tc_filename in finished_hook_called)
                    expected_minsize = tc.get('file_minsize', 10000)
                    if expected_minsize is not None:
                        if params.get('test'):
                            expected_minsize = max(expected_minsize, 10000)
                        got_fsize = os.path.getsize(tc_filename)
                        assertGreaterEqual(
                            self, got_fsize, expected_minsize,
                            f'Expected {tc_filename} to be at least {format_bytes(expected_minsize)}, '

Review comment (bug):
these messages are incorrect because if there is `playlist_count` or `playlist_maxcount` in the `test_case`, then we are never extracting all of the entries (we are only extracting 1 more than the expected count)

Code after:
                    try_num += 1
                except YoutubeDLError as err:
                    if match_exception(err):
                        return
                    raise
                else:
                    break

            if is_playlist:
                self.assertTrue(res_dict['_type'] in ['playlist', 'multi_video'])
                self.assertTrue('entries' in res_dict)
                expect_info_dict(self, res_dict, test_case.get('info_dict', {}))

            num_entries = len(res_dict.get('entries', []))
            if 'playlist_mincount' in test_case:
                mincount = test_case['playlist_mincount']
                assertGreaterEqual(
                    self, num_entries, mincount,
                    f'Expected at least {mincount} entries in playlist {test_url}, but got only {num_entries}')
            if 'playlist_count' in test_case:
                count = test_case['playlist_count']
                got = num_entries if num_entries <= count else 'more'
                self.assertEqual(
                    num_entries, count,
                    f'Expected exactly {count} entries in playlist {test_url}, but got {got}')
            if 'playlist_maxcount' in test_case:
                maxcount = test_case['playlist_maxcount']
                assertLessEqual(
                    self, num_entries, maxcount,
                    f'Expected at most {maxcount} entries in playlist {test_url}, but got more')
            if 'playlist_duration_sum' in test_case:
                got_duration = sum(e['duration'] for e in res_dict['entries'])
                self.assertEqual(
                    test_case['playlist_duration_sum'], got_duration)

            # Generalize both playlists and single videos to unified format for
            # simplicity
            if 'entries' not in res_dict:
                res_dict['entries'] = [res_dict]

            for tc_num, tc in enumerate(test_cases):
                tc_res_dict = res_dict['entries'][tc_num]
                # First, check test cases' data against extracted data alone
                expect_info_dict(self, tc_res_dict, tc.get('info_dict', {}))
                if tc_res_dict.get('_type', 'video') != 'video':
                    continue
                # Now, check downloaded file consistency
                tc_filename = get_tc_filename(tc)
                if not test_case.get('params', {}).get('skip_download', False):
                    self.assertTrue(os.path.exists(tc_filename), msg='Missing file ' + tc_filename)
                    self.assertTrue(tc_filename in finished_hook_called)