Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KeynesYouDigIt committed Jun 1, 2019
1 parent ae3620c commit 46d3635
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
25 changes: 15 additions & 10 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,26 @@ def _add_empty_translations(self, warnings=None):
for content_type in content_types:
if content_type not in self._translations[lang][path]:
missing_warning = self._generate_missing_translation_warning(
lang)
lang
)
if missing_warning not in warnings:
warnings.append(missing_warning)
self._translations[lang][path][content_type] = u"-"

def _generate_missing_translation_warning(self, lang):
if lang == 'default':
return ('\tDefault language not set,'
+ ' with missing default translations.'
' Please consider setting a `default_language` in your'
+ ' settings tab to insure questions and options appear'
+ ' as expected.')

return ('\tMissing field translations found for ' + lang
+ ' field may not appear as expected')
if lang == "default":
return (
"\tDefault language not set," + " with missing default translations."
" Please consider setting a `default_language` in your"
+ " settings tab to insure questions and options appear"
+ " as expected."
)

return (
"\tMissing field translations found for "
+ lang
+ " field may not appear as expected"
)

def _setup_media(self):
"""
Expand Down
34 changes: 22 additions & 12 deletions pyxform/tests_v1/test_language_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ def test_label_with_unknown_subtag_should_warn(self):

self.assertTrue(len(warnings) == 1)
self.assertTrue(
'do not contain valid machine-readable codes: English (schm). Learn more' in warnings[0])
"do not contain valid machine-readable codes: English (schm). Learn more"
in warnings[0]
)
os.unlink(tmp.name)

def test_missing_translation_no_default_lang_media_has_no_language(self):
# form should test media tag w NO default language set.
survey = self.md_to_pyxform_survey("""
survey = self.md_to_pyxform_survey(
"""
| survey | | | | |
| | type | name | label::English (en) | media::image|
| | integer | nums | How many nums? | opt1.jpg |
""")
"""
)

warnings = []
tmp = tempfile.NamedTemporaryFile(suffix='.xml', delete=False)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
tmp.close()
survey.print_xform_to_file(tmp.name, warnings=warnings)

Expand All @@ -89,14 +93,16 @@ def test_missing_translation_no_default_lang_media_has_no_language(self):
os.unlink(tmp.name)

def test_missing_translation_media(self):
survey = self.md_to_pyxform_survey("""
survey = self.md_to_pyxform_survey(
"""
| survey | | | | | |
| | type | name | label::English (en) | label::French (fr) | media::image::French (fr)|
| | integer | nums | How many nums? | Combien noms? | opt1.jpg |
""")
"""
)

warnings = []
tmp = tempfile.NamedTemporaryFile(suffix='.xml', delete=False)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
tmp.close()
survey.print_xform_to_file(tmp.name, warnings=warnings)

Expand All @@ -106,14 +112,16 @@ def test_missing_translation_media(self):
os.unlink(tmp.name)

def test_missing_translation_hint(self):
survey = self.md_to_pyxform_survey("""
survey = self.md_to_pyxform_survey(
"""
| survey | | | | | |
| | type | name | label::English (en) | label::French (fr) | hint::French (fr) |
| | integer | nums | How many nums? | Combien noms? | noms est nombres |
""")
"""
)

warnings = []
tmp = tempfile.NamedTemporaryFile(suffix='.xml', delete=False)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
tmp.close()
survey.print_xform_to_file(tmp.name, warnings=warnings)

Expand All @@ -123,15 +131,17 @@ def test_missing_translation_hint(self):
os.unlink(tmp.name)

def test_default_language_only_should_not_warn(self):
survey = self.md_to_pyxform_survey("""
survey = self.md_to_pyxform_survey(
"""
| survey | | | | |
| | type | name | label | choice_filter |
| | select_one opts | opt | My opt | fake = 1 |
| choices| | | | |
| | list_name | name | label | fake |
| | opts | opt1 | Opt1 | 1 |
| | opts | opt2 | Opt2 | 1 |
""")
"""
)

warnings = []
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
Expand Down

0 comments on commit 46d3635

Please sign in to comment.