Skip to content

Commit

Permalink
Addressed review feedback #5187
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko committed Oct 21, 2024
1 parent 0554a8d commit f01f244
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
redirect, request, send_file, url_for,
send_from_directory, session)
from flask_babel import Babel
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
from website.flask_commonmark import Commonmark
from flask_compress import Compress
from urllib.parse import quote_plus
Expand Down
8 changes: 0 additions & 8 deletions gettext_with_fallback.py

This file was deleted.

2 changes: 1 addition & 1 deletion hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import lru_cache

import lark
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
from lark import Lark
from lark.exceptions import UnexpectedEOF, UnexpectedCharacters, VisitError
from lark import Tree, Transformer, visitors, v_args
Expand Down
2 changes: 1 addition & 1 deletion hedy_error.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hedy
import hedy_translation
import re
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext


# TODO: we should not maintain a list like this. Translation of exception arguments should happen when the exception
Expand Down
73 changes: 73 additions & 0 deletions tests/tests_z_yamlfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,76 @@ def test_load_yaml_equivalent(self):
print(
f'YAML loading takes {original_seconds / n} seconds, unpickling takes {cached_seconds / n}'
f'({original_seconds / cached_seconds:.1f}x faster)')

# Merging of YAML content
# Key of type dict
def test_merge_dicts_prefers_source(self):
result = YamlFile.merge_yaml({"key1": "source"}, {"key1": "fallback"})
self.assertEqual({"key1": "source"}, result)

def test_merge_dicts_uses_fallback_if_source_key_not_present(self):
result = YamlFile.merge_yaml({}, {"key1": "fallback"})
self.assertEqual({"key1": "fallback"}, result)

def test_merge_dicts_skips_key_if_not_present_in_fallback_empty(self):
result = YamlFile.merge_yaml({"key1": "source"}, {})
self.assertEqual({}, result)

def test_merge_dicts_skips_key_if_not_present_in_fallback(self):
result = YamlFile.merge_yaml({"key2": "source"}, {"key1": "fallback"})
self.assertEqual({"key1": "fallback"}, result)

# Key of type list
def test_merge_lists_prefers_source(self):
result = YamlFile.merge_yaml({"key1": ["a", "b"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["a", "b"]}, result)

def test_merge_lists_skips_key_if_not_present_in_fallback(self):
result = YamlFile.merge_yaml({"key1": ["a", "b"]}, {})
self.assertEqual({}, result)

def test_merge_lists_uses_fallback_if_source_key_not_present_empty(self):
result = YamlFile.merge_yaml({}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["c", "d"]}, result)

def test_merge_lists_uses_fallback_if_source_key_not_present(self):
result = YamlFile.merge_yaml({"key2": ["a", "b"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["c", "d"]}, result)

# Elements in list
def test_merge_lists_values_prefers_source(self):
result = YamlFile.merge_yaml({"key1": [None, "b"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["c", "b"]}, result)

def test_merge_lists_values_uses_fallback_if_value_is_empty(self):
result = YamlFile.merge_yaml({"key1": ["", "b"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["c", "b"]}, result)

def test_merge_lists_values_prefers_len_of_fallback(self):
result = YamlFile.merge_yaml({"key1": ["a", "b", "e"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["a", "b"]}, result)

def test_merge_lists_values_prefers_source_values(self):
result = YamlFile.merge_yaml({"key1": ["a"]}, {"key1": ["c", "d"]})
self.assertEqual({"key1": ["a", "d"]}, result)

# Keys with mismatched types
def test_merge_dicts_prefers_fallback_type_dict(self):
result = YamlFile.merge_yaml({"key1": ["a", "b"]}, {"key1": {"a": "c", "b": "d"}})
self.assertEqual({"key1": {"a": "c", "b": "d"}}, result)

def test_merge_dicts_prefers_fallback_type_str(self):
result = YamlFile.merge_yaml({"key1": ["a", "b"]}, {"key1": "string value"})
self.assertEqual({"key1": "string value"}, result)

def test_merge_dicts_prefers_fallback_type_list(self):
result = YamlFile.merge_yaml({"key1": {"a": "c", "b": "d"}}, {"key1": ["a", "b"]})
self.assertEqual({"key1": ["a", "b"]}, result)

def test_merge_dicts_prefers_fallback_type_string(self):
result = YamlFile.merge_yaml({"key1": {"a": "c", "b": "d"}}, {"key1": "string value"})
self.assertEqual({"key1": "string value"}, result)

def test_merge_dicts_prefers_fallback_type_bool(self):
result = YamlFile.merge_yaml({"key1": True}, {"key1": "string value"})
self.assertEqual({"key1": True}, result)
2 changes: 1 addition & 1 deletion translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ msgid "star"
msgstr "a star"

msgid "start_learning"
msgstr "Start learning EN"
msgstr "Start learning"

msgid "start_quiz"
msgstr "Start quiz"
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from email_validator import EmailNotValidError, validate_email
from flask_babel import format_date, format_datetime, format_timedelta
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
from ruamel import yaml
import commonmark

Expand Down
2 changes: 1 addition & 1 deletion website/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import make_response, request
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

import utils
from website.flask_helpers import render_template
Expand Down
2 changes: 1 addition & 1 deletion website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from botocore.exceptions import NoCredentialsError
from flask import g, request, session, redirect
from flask_babel import force_locale
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

import utils
from config import config
Expand Down
2 changes: 1 addition & 1 deletion website/auth_pages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from flask import make_response, redirect, request, session
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

from config import config
from safe_format import safe_format
Expand Down
2 changes: 1 addition & 1 deletion website/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask import make_response, redirect, request, session
from jinja_partials import render_partial
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

import utils
from config import config
Expand Down
2 changes: 1 addition & 1 deletion website/feedback.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from flask import request, make_response, render_template
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import json
import uuid
from collections import defaultdict
Expand Down
2 changes: 1 addition & 1 deletion website/for_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bs4 import BeautifulSoup
from flask import g, make_response, request, session, url_for, redirect
from jinja_partials import render_partial
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import jinja_partials

import hedy
Expand Down
2 changes: 1 addition & 1 deletion website/parsons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import g, make_response
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

from .website_module import WebsiteModule, route

Expand Down
2 changes: 1 addition & 1 deletion website/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests
from flask import make_response, request, session
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext

from safe_format import safe_format
from hedy_content import ALL_KEYWORD_LANGUAGES, ALL_LANGUAGES, COUNTRIES
Expand Down
2 changes: 1 addition & 1 deletion website/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional

from flask import g, make_response, request
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import jinja_partials
import hedy_content

Expand Down
2 changes: 1 addition & 1 deletion website/public_adventures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from flask import g, request, make_response
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import json

import hedy
Expand Down
2 changes: 1 addition & 1 deletion website/tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import make_response, request, g
from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import jinja_partials
import uuid

Expand Down
2 changes: 1 addition & 1 deletion website/user_activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from gettext_with_fallback import gettext
from website.flask_helpers import gettext_with_fallback as gettext
import os
from flask import make_response, request, session

Expand Down

0 comments on commit f01f244

Please sign in to comment.