Skip to content

Commit babad84

Browse files
authored
Require compare-locales in fluent.migrate (#47)
Make compare-locales a hard requirement for running and testing fluent.migrate which already largely depends on it anyways. This reduces the complexity of imports as well as the burden of deciding if a TestCase depends on compare-locales or not. It also makes it less probable to accidentally skip migration tests with `python -m unittest discover`. The following commands may be used to run tests: - python setup.py test - Only syntax tests in tests/syntax will be run. compare-locales is not required. - python -m unittest discover - All tests will be run. If compare-locales is missing, tests will error. It's possible to run only syntax or only migrate tests by specifying the starting director on the CLI: python -m unittest discover -s tests/syntax python -m unittest discover -s tests/migrate - tox - Tox will create different envs one if which is py27-cl. It contains compare-locales and is configured to run both tests/syntax and tests/migrate tests. All other tests only run tests/syntax.
1 parent 466f893 commit babad84

File tree

11 files changed

+19
-78
lines changed

11 files changed

+19
-78
lines changed

fluent/migrate/context.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
from fluent.syntax.parser import FluentParser
1515
from fluent.syntax.serializer import FluentSerializer
1616
from fluent.util import fold
17-
try:
18-
from compare_locales.parser import getParser
19-
except ImportError:
20-
def getParser(path):
21-
raise RuntimeError('compare-locales required')
17+
from compare_locales.parser import getParser
2218

2319
from .cldr import get_plural_categories
2420
from .transforms import Source

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
package_data={
2222
'fluent.migrate': ['cldr_data/*']
2323
},
24-
tests_require=['six']
24+
tests_require=['six'],
25+
test_suite='tests.syntax'
2526
)

tests/migrate/test_concat.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
from __future__ import unicode_literals
33

44
import unittest
5+
from compare_locales.parser import PropertiesParser, DTDParser
56

67
import fluent.syntax.ast as FTL
7-
try:
8-
from compare_locales.parser import PropertiesParser, DTDParser
9-
except ImportError:
10-
DTDParser = PropertiesParser = None
11-
128
from fluent.migrate.util import parse, ftl_message_to_json
139
from fluent.migrate.helpers import EXTERNAL_ARGUMENT, MESSAGE_REFERENCE
1410
from fluent.migrate.transforms import evaluate, CONCAT, COPY, REPLACE
@@ -23,7 +19,6 @@ def get_source(self, path, key):
2319
return self.strings.get(key, None).val
2420

2521

26-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
2722
class TestConcatCopy(MockContext):
2823
def setUp(self):
2924
self.strings = parse(PropertiesParser, '''
@@ -120,7 +115,6 @@ def test_concat_whitespace_end(self):
120115
)
121116

122117

123-
@unittest.skipUnless(DTDParser, 'compare-locales required')
124118
class TestConcatLiteral(MockContext):
125119
def setUp(self):
126120
self.strings = parse(DTDParser, '''
@@ -149,7 +143,6 @@ def test_concat_literal(self):
149143
)
150144

151145

152-
@unittest.skipUnless(DTDParser, 'compare-locales required')
153146
class TestConcatInterpolate(MockContext):
154147
def setUp(self):
155148
self.strings = parse(DTDParser, '''
@@ -192,7 +185,6 @@ def test_concat_expression(self):
192185
)
193186

194187

195-
@unittest.skipUnless(DTDParser, 'compare-locales required')
196188
class TestConcatReplace(MockContext):
197189
def setUp(self):
198190
self.strings = parse(DTDParser, '''

tests/migrate/test_context.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
import os
55
import logging
66
import unittest
7-
8-
try:
9-
import compare_locales
10-
except ImportError:
11-
compare_locales = None
7+
import compare_locales
128

139
import fluent.syntax.ast as FTL
14-
1510
from fluent.migrate.errors import (
1611
EmptyLocalizationError, NotSupportedError, UnreadableReferenceError)
1712
from fluent.migrate.util import ftl, ftl_resource_to_json, to_json
@@ -24,7 +19,6 @@ def here(*parts):
2419
return os.path.join(dirname, *parts)
2520

2621

27-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
2822
class TestMergeContext(unittest.TestCase):
2923
def setUp(self):
3024
self.ctx = MergeContext(
@@ -250,7 +244,6 @@ def test_missing_reference_file(self):
250244
self.ctx.add_transforms('some.ftl', 'missing.ftl', [])
251245

252246

253-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
254247
class TestMissingLocalizationFiles(unittest.TestCase):
255248
def setUp(self):
256249
# Silence all logging.
@@ -313,7 +306,6 @@ def test_all_files_missing(self):
313306
])
314307

315308

316-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
317309
class TestMissingLocalizationStrings(unittest.TestCase):
318310
maxDiff = None
319311

@@ -528,7 +520,6 @@ def test_missing_string_in_one_of_attributes(self):
528520
)
529521

530522

531-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
532523
class TestExistingTarget(unittest.TestCase):
533524
maxDiff = None
534525

tests/migrate/test_context_real_examples.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33

44
import os
55
import unittest
6-
7-
try:
8-
import compare_locales
9-
except ImportError:
10-
compare_locales = None
6+
import compare_locales
117

128
import fluent.syntax.ast as FTL
13-
149
from fluent.migrate.util import ftl_resource_to_json, to_json
1510
from fluent.migrate.context import MergeContext
1611
from fluent.migrate.helpers import EXTERNAL_ARGUMENT, MESSAGE_REFERENCE
@@ -24,7 +19,6 @@ def here(*parts):
2419
return os.path.join(dirname, *parts)
2520

2621

27-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
2822
class TestMergeAboutDownloads(unittest.TestCase):
2923
def setUp(self):
3024
self.ctx = MergeContext(
@@ -279,7 +273,6 @@ def test_merge_context_some_messages(self):
279273
)
280274

281275

282-
@unittest.skipUnless(compare_locales, 'compare-locales requried')
283276
class TestMergeAboutDialog(unittest.TestCase):
284277
maxDiff = None
285278

tests/migrate/test_copy.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
from __future__ import unicode_literals
33

44
import unittest
5+
from compare_locales.parser import PropertiesParser, DTDParser
56

67
import fluent.syntax.ast as FTL
7-
try:
8-
from compare_locales.parser import PropertiesParser, DTDParser
9-
except ImportError:
10-
PropertiesParser = DTDParser = None
11-
128
from fluent.migrate.util import parse, ftl_message_to_json
139
from fluent.migrate.transforms import evaluate, COPY
1410

@@ -20,7 +16,6 @@ def get_source(self, path, key):
2016
return self.strings.get(key, None).val
2117

2218

23-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
2419
class TestCopy(MockContext):
2520
def setUp(self):
2621
self.strings = parse(PropertiesParser, '''
@@ -71,7 +66,6 @@ def test_copy_escape_unicode_end(self):
7166
)
7267

7368

74-
@unittest.skipUnless(DTDParser, 'compare-locales required')
7569
class TestCopyAttributes(MockContext):
7670
def setUp(self):
7771
self.strings = parse(DTDParser, '''

tests/migrate/test_merge.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
from __future__ import unicode_literals
33

44
import unittest
5+
from compare_locales.parser import PropertiesParser, DTDParser
56

67
import fluent.syntax.ast as FTL
78
from fluent.syntax.parser import FluentParser
8-
try:
9-
from compare_locales.parser import PropertiesParser, DTDParser
10-
except ImportError:
11-
PropertiesParser = DTDParser = None
12-
139
from fluent.migrate.util import parse, ftl, ftl_resource_to_json
1410
from fluent.migrate.merge import merge_resource
1511
from fluent.migrate.transforms import COPY
@@ -25,8 +21,6 @@ def get_source(self, path, key):
2521
return translation.val
2622

2723

28-
@unittest.skipUnless(PropertiesParser and DTDParser,
29-
'compare-locales required')
3024
class TestMergeMessages(MockContext):
3125
maxDiff = None
3226

@@ -129,8 +123,6 @@ def test_merge_three_way(self):
129123
)
130124

131125

132-
@unittest.skipUnless(PropertiesParser and DTDParser,
133-
'compare-locales required')
134126
class TestMergeAllEntries(MockContext):
135127
def setUp(self):
136128
self.en_us_ftl = parse(FluentParser, ftl('''
@@ -245,8 +237,6 @@ def test_merge_three_way(self):
245237
)
246238

247239

248-
@unittest.skipUnless(PropertiesParser and DTDParser,
249-
'compare-locales required')
250240
class TestMergeSubset(MockContext):
251241
def setUp(self):
252242
self.en_us_ftl = parse(FluentParser, ftl('''

tests/migrate/test_plural.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
from __future__ import unicode_literals
33

44
import unittest
5+
from compare_locales.parser import PropertiesParser
56

67
import fluent.syntax.ast as FTL
7-
try:
8-
from compare_locales.parser import PropertiesParser
9-
except ImportError:
10-
PropertiesParser = None
11-
128
from fluent.migrate.util import parse, ftl_message_to_json
139
from fluent.migrate.helpers import EXTERNAL_ARGUMENT
1410
from fluent.migrate.transforms import evaluate, PLURALS, REPLACE_IN_TEXT
@@ -25,7 +21,6 @@ def get_source(self, path, key):
2521
return self.strings.get(key, None).val
2622

2723

28-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
2924
class TestPlural(MockContext):
3025
def setUp(self):
3126
self.strings = parse(PropertiesParser, '''
@@ -79,7 +74,6 @@ def test_plural_too_many_variants(self):
7974
)
8075

8176

82-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
8377
class TestPluralLiteral(MockContext):
8478
def setUp(self):
8579
self.strings = parse(PropertiesParser, '''
@@ -108,7 +102,6 @@ def test_plural_literal(self):
108102
)
109103

110104

111-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
112105
class TestPluralReplace(MockContext):
113106
def setUp(self):
114107
self.strings = parse(PropertiesParser, '''
@@ -143,7 +136,6 @@ def test_plural_replace(self):
143136
)
144137

145138

146-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
147139
class TestOneCategory(MockContext):
148140
# Plural categories corresponding to Turkish (tr).
149141
plural_categories = ('other',)
@@ -177,7 +169,6 @@ def test_no_select_expression(self):
177169
)
178170

179171

180-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
181172
class TestManyCategories(MockContext):
182173
# Plural categories corresponding to Polish (pl).
183174
plural_categories = ('one', 'few', 'many', 'other')

tests/migrate/test_replace.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
from __future__ import unicode_literals
33

44
import unittest
5+
from compare_locales.parser import PropertiesParser
56

67
import fluent.syntax.ast as FTL
7-
try:
8-
from compare_locales.parser import PropertiesParser
9-
except ImportError:
10-
PropertiesParser = None
11-
128
from fluent.migrate.util import parse, ftl_message_to_json
139
from fluent.migrate.helpers import EXTERNAL_ARGUMENT
1410
from fluent.migrate.transforms import evaluate, REPLACE
@@ -23,7 +19,6 @@ def get_source(self, path, key):
2319
return self.strings.get(key, None).val
2420

2521

26-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
2722
class TestReplace(MockContext):
2823
def setUp(self):
2924
self.strings = parse(PropertiesParser, '''

tests/migrate/test_source.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
from __future__ import unicode_literals
33

44
import unittest
5-
6-
try:
7-
from compare_locales.parser import PropertiesParser, DTDParser
8-
except ImportError:
9-
PropertiesParser = DTDParser = None
5+
from compare_locales.parser import PropertiesParser, DTDParser
106

117
import fluent.syntax.ast as FTL
12-
138
from fluent.migrate.errors import NotSupportedError
149
from fluent.migrate.transforms import Source, COPY, PLURALS, REPLACE
1510
from fluent.migrate.util import parse
@@ -63,7 +58,6 @@ def get_source(self, _path, key):
6358
return self.strings[key].val
6459

6560

66-
@unittest.skipUnless(PropertiesParser, 'compare-locales required')
6761
class TestProperties(MockContext):
6862
def setUp(self):
6963
self.strings = parse(PropertiesParser, '''
@@ -97,7 +91,6 @@ def test_html_entity(self):
9791
self.assertEqual(source(self), '<⇧⌘K>')
9892

9993

100-
@unittest.skipUnless(DTDParser, 'compare-locales required')
10194
class TestDTD(MockContext):
10295
def setUp(self):
10396
self.strings = parse(DTDParser, '''

0 commit comments

Comments
 (0)