mirror of https://github.com/zulip/zulip.git
python: Replace silly uses of filter().
The test_management_commands use in particular was causing pickling errors when the test failed, because Python 3 filter returns an iterator, not a list. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
5c9d56d2f7
commit
d3e8af4ad2
|
@ -42,10 +42,7 @@ def check_html_templates(templates: Iterable[str], all_dups: bool, fix: bool) ->
|
|||
# there are also cases where Casper deliberately uses invalid HTML,
|
||||
# so we exclude them from our linter.
|
||||
logging.basicConfig(format='%(levelname)s:%(message)s')
|
||||
templates = filter(
|
||||
lambda fn: ('casperjs' not in fn),
|
||||
templates)
|
||||
templates = sorted(list(templates))
|
||||
templates = sorted(fn for fn in templates if 'casperjs' not in fn)
|
||||
# Use of underscore templates <%= %>.
|
||||
if 'templates/zerver/team.html' in templates:
|
||||
templates.remove('templates/zerver/team.html')
|
||||
|
@ -99,12 +96,8 @@ def check_html_templates(templates: Iterable[str], all_dups: bool, fix: bool) ->
|
|||
return bad_ids_dict
|
||||
|
||||
bad_ids_list: List[str] = []
|
||||
archive_templates = list(filter(
|
||||
lambda fn: ('templates/zerver/archive' in fn),
|
||||
templates))
|
||||
templates = list(filter(
|
||||
lambda fn: ('templates/zerver/archive' not in fn),
|
||||
templates))
|
||||
archive_templates = [fn for fn in templates if 'templates/zerver/archive' in fn]
|
||||
templates = [fn for fn in templates if 'templates/zerver/archive' not in fn]
|
||||
|
||||
bad_ids_list += list(check_for_duplicate_ids(archive_templates).keys())
|
||||
bad_ids_list += list(check_for_duplicate_ids(templates).keys())
|
||||
|
|
|
@ -497,10 +497,10 @@ def get_mobile_push_content(rendered_content: str) -> str:
|
|||
return elem.text or ''
|
||||
|
||||
def format_as_quote(quote_text: str) -> str:
|
||||
quote_text_list = filter(None, quote_text.split('\n')) # Remove empty lines
|
||||
quote_text = '\n'.join(map(lambda x: "> "+x, quote_text_list))
|
||||
quote_text += '\n'
|
||||
return quote_text
|
||||
return "".join(
|
||||
f"> {line}\n" for line in quote_text.splitlines()
|
||||
if line # Remove empty lines
|
||||
)
|
||||
|
||||
def render_olist(ol: lxml.html.HtmlElement) -> str:
|
||||
items = []
|
||||
|
|
|
@ -297,8 +297,9 @@ def send_custom_email(users: List[UserProfile], options: Dict[str, Any]) -> None
|
|||
inline_template(email_filename)
|
||||
|
||||
# Finally, we send the actual emails.
|
||||
for user_profile in filter(lambda user:
|
||||
not options.get('admins_only') or user.is_realm_admin, users):
|
||||
for user_profile in users:
|
||||
if options.get('admins_only') and not user_profile.is_realm_admin:
|
||||
continue
|
||||
context = {
|
||||
'realm_uri': user_profile.realm.uri,
|
||||
'realm_name': user_profile.realm.name,
|
||||
|
|
|
@ -174,13 +174,12 @@ class TestCommandsCanStart(TestCase):
|
|||
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.commands = filter(
|
||||
lambda filename: filename != '__init__',
|
||||
map(
|
||||
lambda file: os.path.basename(file).replace('.py', ''),
|
||||
glob.iglob('*/management/commands/*.py')
|
||||
)
|
||||
)
|
||||
self.commands = [
|
||||
command
|
||||
for filename in glob.iglob('*/management/commands/*.py')
|
||||
for command in [os.path.basename(filename).replace('.py', '')]
|
||||
if command != '__init__'
|
||||
]
|
||||
|
||||
@slow("Aggregate of runs dozens of individual --help tests")
|
||||
def test_management_commands_show_help(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue