Repository navigation
Test Request: Placeholder explanations #7 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """Placeholder token explanation.""" | ||
|
|
||
| from typing import Any, Dict, List | ||
|
|
||
| from localizationkit.tests.test_case import LocalizationTestCase | ||
|
|
||
|
|
||
| class PlaceholderTokenExplanation(LocalizationTestCase): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this isn't a common requirement. We should probably make it opt-in.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PoonamBaxi This issue is still there. Note: I've had to remove everyone from the Outlook Mobile team for security purposes, so let me know if you can't push any more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dale (@dalemyers) Sorry not sure how I missed adding the class method for Can you take a look please? Thanks!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed this now. For future contributions, you'll need to fork and open a PR that way (just as standard).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dale (@dalemyers) Thanks for pushing the fix, I am not sure I followed your comment above. I had forked the master branch and used that for the change, also I fixed the issue locally but now cannot push to this branch anymore as my permissions are not working. |
||
| """Check the placeholder tokens in strings have explanation in comments.""" | ||
|
|
||
| @classmethod | ||
| def name(cls) -> str: | ||
| return "placeholder_token_explanation" | ||
|
|
||
| @classmethod | ||
| def default_settings(cls) -> Dict[str, Any]: | ||
| return {} | ||
|
|
||
| @classmethod | ||
| def is_opt_in(cls) -> bool: | ||
| return True | ||
|
|
||
| def run_test(self) -> List[str]: | ||
|
|
||
| violations = [] | ||
|
|
||
| for string in self.collection.localized_strings: | ||
| tokens = set(string.tokens()) | ||
| comment_tokens = set(string.comment_tokens()) | ||
|
|
||
| extra_in_tokens = tokens - comment_tokens | ||
| extra_in_comments = comment_tokens - tokens | ||
|
|
||
| if len(extra_in_tokens) != 0: | ||
| violations.append(f"Tokens are not described in the comment ({extra_in_tokens}): {string}") | ||
|
|
||
| if len(extra_in_comments) != 0: | ||
| violations.append(f"Extra tokens appear in the comment ({extra_in_comments}): {string}") | ||
|
|
||
| return violations | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Placeholder token explanation tests.""" | ||
|
|
||
| # pylint: disable=line-too-long | ||
|
|
||
| import os | ||
| import sys | ||
| import unittest | ||
|
|
||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.abspath(__file__), "..", ".."))) | ||
| import localizationkit | ||
|
|
||
|
|
||
| class PlaceholderTokenExplanationTests(unittest.TestCase): | ||
| """Placeholder token explanation tests.""" | ||
|
|
||
| def setUp(self): | ||
| current_file_path = os.path.abspath(__file__) | ||
| current_folder_path = os.path.dirname(current_file_path) | ||
| self.config_path = os.path.abspath(os.path.join(current_folder_path, "config.toml")) | ||
| self.configuration = localizationkit.Configuration.from_file(self.config_path) | ||
|
|
||
| def test_placeholder_token_explanation(self): | ||
| """Test that all placeholder token explanations exists in comments""" | ||
| test_cases = [ | ||
| ( | ||
| True, | ||
| localizationkit.LocalizedString( | ||
| "Key", "This is a string with no tokens", "Some comment", "en" | ||
| ), | ||
| ), | ||
| ( | ||
| True, | ||
| localizationkit.LocalizedString( | ||
| "Key", "This is a string with one token: %@", "Some comment %@ token explanation", "en" | ||
| ), | ||
| ), | ||
| ( | ||
| True, | ||
| localizationkit.LocalizedString( | ||
| "Key", "This is a string with two tokens: %1$@ %2$@", "Some comment %1$@ token explanantion %2$@ token explanantion", "en" | ||
| ), | ||
| ), | ||
| ( | ||
| False, | ||
| localizationkit.LocalizedString( | ||
| "Key", | ||
| "This is a string with two tokens: %1$@ %2$@", | ||
| "Some comment missing all token explanation", | ||
| "en", | ||
| ), | ||
| ), | ||
| ( | ||
| False, | ||
| localizationkit.LocalizedString( | ||
| "Key", "This is a string with two tokens: %1$@ %2$@", "Some comment %@ token explanation missing some token explanantion", "en" | ||
| ), | ||
| ), | ||
| ( | ||
| False, | ||
| localizationkit.LocalizedString( | ||
| "Key", "This is a string", "Some comment %@ extra token explanation", "en" | ||
| ), | ||
| ), | ||
| ] | ||
|
|
||
| for expected_result, string in test_cases: | ||
| collection = localizationkit.LocalizedCollection([string]) | ||
| test = localizationkit.tests.placeholder_token_explanation.PlaceholderTokenExplanation( | ||
| self.configuration, | ||
| collection | ||
| ) | ||
| result = test.execute() | ||
|
PoonamBaxi marked this conversation as resolved.
Resolved
|
||
| self.assertEqual(expected_result, result.succeeded()) | ||
Uh oh!
There was an error while loading. Please reload this page.