Merge lp:~thelinuxguy/openlp/fix-regex into lp:openlp

Proposed by Simon Hanna
Status: Merged
Merged at revision: 2832
Proposed branch: lp:~thelinuxguy/openlp/fix-regex
Merge into: lp:openlp
Diff against target: 45 lines (+13/-3)
2 files modified
openlp/core/common/i18n.py (+3/-2)
tests/functional/openlp_core/common/test_i18n.py (+10/-1)
To merge this branch: bzr merge lp:~thelinuxguy/openlp/fix-regex
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Raoul Snyman Approve
Review via email: mp+353793@code.launchpad.net

Description of the change

Fix the following warning which was displayed when running OpenLP in the cli

/home/sim/dev/openlp/trunk/openlp/core/common/i18n.py:274: FutureWarning: Possible nested set at position 1
  if re.match(r'[[].*[]]', language):

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Tests failed, please see https://ci.openlp.io/job/MP-02-Linux_Tests/27/ for more details

Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/common/i18n.py'
2--- openlp/core/common/i18n.py 2018-04-12 19:15:56 +0000
3+++ openlp/core/common/i18n.py 2018-08-27 14:18:33 +0000
4@@ -271,9 +271,10 @@
5 language = Settings().value('core/language')
6 language = str(language)
7 log.info("Language file: '{language}' Loaded from conf file".format(language=language))
8- if re.match(r'[[].*[]]', language):
9+ m = re.match(r'\[(.*)\]', language)
10+ if m:
11 LanguageManager.auto_language = True
12- language = re.sub(r'[\[\]]', '', language)
13+ language = m.group(1)
14 return language
15
16 @staticmethod
17
18=== modified file 'tests/functional/openlp_core/common/test_i18n.py'
19--- tests/functional/openlp_core/common/test_i18n.py 2017-12-29 09:15:48 +0000
20+++ tests/functional/openlp_core/common/test_i18n.py 2018-08-27 14:18:33 +0000
21@@ -27,7 +27,8 @@
22
23 from openlp.core.common import is_macosx
24 from openlp.core.common.i18n import LANGUAGES, Language, UiStrings, get_language, get_locale_key, get_natural_key, \
25- translate
26+ translate, LanguageManager
27+from openlp.core.common.settings import Settings
28
29
30 def test_languages_type():
31@@ -158,6 +159,14 @@
32 assert first_instance is second_instance, 'Two UiStrings objects should be the same instance'
33
34
35+def test_get_language_from_settings():
36+ assert LanguageManager.get_language() == 'en'
37+
38+def test_get_language_from_settings_returns_unchanged_if_unknown_format():
39+ Settings().setValue('core/language', '(foobar)')
40+ assert LanguageManager.get_language() == '(foobar)'
41+
42+
43 def test_translate():
44 """
45 Test the translate() function