Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
- whitespace around a print function
- one more switch to sorted() from ().sort()
- give temp dirs distinctive names
- allow for .pyo files too
  • Loading branch information
jamadden committed May 2, 2017
1 parent d6b9465 commit dbfdedf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/zope/app/locales/extract.py
Expand Up @@ -754,16 +754,16 @@ def main(argv=None):
os.mkdir(output_dir)
output_file = os.path.join(output_dir, output_file)

print( "base path: %r\n" \
"search path: %s\n" \
"'site.zcml' location: %s\n" \
"exclude dirs: %r\n" \
"domain: %r\n" \
"include default domain: %r\n" \
"output file: %r\n" \
"Python only: %r" \
% (base_dir, path, site_zcml, exclude_dirs, domain,
include_default_domain, output_file, python_only))
print("base path: %r\n" \
"search path: %s\n" \
"'site.zcml' location: %s\n" \
"exclude dirs: %r\n" \
"domain: %r\n" \
"include default domain: %r\n" \
"output file: %r\n" \
"Python only: %r" \
% (base_dir, path, site_zcml, exclude_dirs, domain,
include_default_domain, output_file, python_only))

maker = POTMaker(output_file, path)
maker.add(py_strings(path, domain, exclude=exclude_dirs), base_dir)
Expand Down
3 changes: 1 addition & 2 deletions src/zope/app/locales/pygettext.py
Expand Up @@ -342,8 +342,7 @@ def write(self, fp):
# sort all the entries by their first item.
reverse = {}
for k, v in self.__messages.items():
keys = list(v.keys())
keys.sort()
keys = sorted(v.keys())
reverse.setdefault(tuple(keys), []).append((k, v))
rkeys = reverse.keys()

Expand Down
11 changes: 6 additions & 5 deletions src/zope/app/locales/tests.py
Expand Up @@ -79,7 +79,9 @@ def test_zcml_extraction(self):
/>
</configure>
"""
dirname = tempfile.mkdtemp()
dirname = tempfile.mkdtemp(prefix='zope-app-locales-tests-')
self.addCleanup(shutil.rmtree, dirname)

fn = os.path.join(dirname, 'configure.zcml')
with open(fn, 'wt') as zcmlfile:
zcmlfile.write(zcml)
Expand All @@ -89,7 +91,6 @@ def test_zcml_extraction(self):
self.assertEqual(sorted(strings.keys()),
[u'Test Permission',
u'This test permission is defined in ZCML'])
shutil.rmtree(dirname)


def doctest_POTEntry_sort_order():
Expand Down Expand Up @@ -303,7 +304,8 @@ def test_main_extract(self):
'-s', 'no such file'], 1)
self.assertIn('does not exist', err.getvalue())

temp = tempfile.mkdtemp()
temp = tempfile.mkdtemp(prefix='zope-app-locales-tests-')
self.addCleanup(shutil.rmtree, temp)

# An object that can look like the usual i18n
# marker, but we'll do different things with it for coverage
Expand All @@ -326,7 +328,6 @@ def __add__(self, other):

self.assertIn('Project-Id-Version: Unknown', pot_data)

shutil.rmtree(temp)

def test_py_strings_verify_domain(self):
from zope.app.locales.extract import py_strings
Expand Down Expand Up @@ -368,7 +369,7 @@ def main(self, argv):

def test_extract(self):
me = __file__
if me.endswith(".pyc"):
if me.endswith((".pyc", ".pyo")):
me = me[:-1]
out, _err = self.run_patched(['-d', 'TESTDOMAIN',
'-v', '-a', '-D', '-o', '-', me])
Expand Down

0 comments on commit dbfdedf

Please sign in to comment.