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

Code before:
            if tc.get('expected_exception'):
                continue
            info_dict = tc.get('info_dict', {})
            params = tc.get('params', {})
            if not info_dict.get('id'):
                raise Exception(f'Test {tname} definition incorrect - "id" key is not present')
            elif not info_dict.get('ext') and info_dict.get('_type', 'video') == 'video':
                if params.get('skip_download') and params.get('ignore_no_formats_error'):
                    continue
                raise Exception(f'Test {tname} definition incorrect - "ext" key must be present to define the output file')

        if 'skip' in test_case:
            print_skipping(test_case['skip'])

        for other_ie in other_ies:
            if not other_ie.working():
                print_skipping(f'test depends on {other_ie.ie_key()}IE, marked as not WORKING')

        params = get_params(test_case.get('params', {}))
        params['outtmpl'] = tname + '_' + params['outtmpl']
        if is_playlist and 'playlist' not in test_case:
            params.setdefault('extract_flat', 'in_playlist')
            params.setdefault('playlistend', max(
                test_case.get('playlist_mincount') or -1,
                (test_case.get('playlist_count') or -2) + 1,
                (test_case.get('playlist_maxcount') or -2) + 1))
            params.setdefault('skip_download', True)

        ydl = YoutubeDL(params, auto_init=False)
        ydl.add_default_info_extractors()
        finished_hook_called = set()

        def _hook(status):
            if status['status'] == 'finished':
                finished_hook_called.add(status['filename'])
        ydl.add_progress_hook(_hook)
        expect_warnings(ydl, test_case.get('expected_warnings', []))

        def get_tc_filename(tc):
            return ydl.prepare_filename(dict(tc.get('info_dict', {})))

        res_dict = None

        def match_exception(err):
            expected_exception = test_case.get('expected_exception')
            if not expected_exception:
                return False
            if err.__class__.__name__ == expected_exception:
                return True
            return any(exc.__class__.__name__ == expected_exception for exc in err.exc_info)


Review comment (suggestion):
it's ok to use the default param here, and IMO easier to read
```suggestion
            params.setdefault('playlistend', max(
                test_case.get('playlist_mincount', -1),
                test_case.get('playlist_count', -2) + 1,
                test_case.get('playlist_maxcount', -2) + 1))
```

Code after:
            if tc.get('expected_exception'):
                continue
            info_dict = tc.get('info_dict', {})
            params = tc.get('params', {})
            if not info_dict.get('id'):
                raise Exception(f'Test {tname} definition incorrect - "id" key is not present')
            elif not info_dict.get('ext') and info_dict.get('_type', 'video') == 'video':
                if params.get('skip_download') and params.get('ignore_no_formats_error'):
                    continue
                raise Exception(f'Test {tname} definition incorrect - "ext" key must be present to define the output file')

        if 'skip' in test_case:
            print_skipping(test_case['skip'])

        for other_ie in other_ies:
            if not other_ie.working():
                print_skipping(f'test depends on {other_ie.ie_key()}IE, marked as not WORKING')

        params = get_params(test_case.get('params', {}))
        params['outtmpl'] = tname + '_' + params['outtmpl']
        if is_playlist and 'playlist' not in test_case:
            params.setdefault('playlistend', max(
                test_case.get('playlist_mincount', -1),
                test_case.get('playlist_count', -2) + 1,
                test_case.get('playlist_maxcount', -2) + 1))
            params.setdefault('skip_download', True)
            if 'playlist_duration_sum' not in test_case:
                params.setdefault('extract_flat', 'in_playlist')

        ydl = YoutubeDL(params, auto_init=False)
        ydl.add_default_info_extractors()
        finished_hook_called = set()

        def _hook(status):
            if status['status'] == 'finished':
                finished_hook_called.add(status['filename'])
        ydl.add_progress_hook(_hook)
        expect_warnings(ydl, test_case.get('expected_warnings', []))

        def get_tc_filename(tc):
            return ydl.prepare_filename(dict(tc.get('info_dict', {})))

        res_dict = None

        def match_exception(err):
            expected_exception = test_case.get('expected_exception')
            if not expected_exception:
                return False
            if err.__class__.__name__ == expected_exception:
                return True
            return any(exc.__class__.__name__ == expected_exception for exc in err.exc_info)