Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Used call_command in i18n compilation tests.

Now that call_command does not raise SystemExit any more, we can
use call_command again for testing compilemessages.
  • Loading branch information...
commit c3b56c7cdde661464da4aaa72cafb11c9260d754 1 parent cc4b4d9
Claude Paroz authored May 27, 2012
23  tests/regressiontests/i18n/commands/compilation.py
... ...
@@ -1,8 +1,7 @@
1 1
 import os
2 2
 from io import BytesIO
3 3
 
4  
-from django.core.management import CommandError
5  
-from django.core.management.commands.compilemessages import compile_messages
  4
+from django.core.management import call_command, CommandError
6 5
 from django.test import TestCase
7 6
 from django.test.utils import override_settings
8 7
 from django.utils import translation
@@ -25,11 +24,9 @@ class PoFileTests(MessageCompilationTests):
25 24
 
26 25
     def test_bom_rejection(self):
27 26
         os.chdir(test_dir)
28  
-        # We don't use the django.core.management infrastructure (call_command()
29  
-        # et al) because CommandError's cause exit(1) there. We test the
30  
-        # underlying compile_messages function instead
31  
-        out = BytesIO()
32  
-        self.assertRaises(CommandError, compile_messages, out, locale=self.LOCALE)
  27
+        with self.assertRaisesRegexp(CommandError,
  28
+                "file has a BOM \(Byte Order Mark\)"):
  29
+            call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
33 30
         self.assertFalse(os.path.exists(self.MO_FILE))
34 31
 
35 32
 
@@ -45,11 +42,7 @@ def setUp(self):
45 42
 
46 43
     def test_percent_symbol_in_po_file(self):
47 44
         os.chdir(test_dir)
48  
-        # We don't use the django.core.management infrastructure (call_command()
49  
-        # et al) because CommandError's cause exit(1) there. We test the
50  
-        # underlying compile_messages function instead
51  
-        out = BytesIO()
52  
-        compile_messages(out, locale=self.LOCALE)
  45
+        call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
53 46
         self.assertTrue(os.path.exists(self.MO_FILE))
54 47
 
55 48
 
@@ -64,11 +57,7 @@ class PercentRenderingTests(MessageCompilationTests):
64 57
     def test_percent_symbol_escaping(self):
65 58
         from django.template import Template, Context
66 59
         os.chdir(test_dir)
67  
-        # We don't use the django.core.management infrastructure (call_command()
68  
-        # et al) because CommandError's cause exit(1) there. We test the
69  
-        # underlying compile_messages function instead
70  
-        out = BytesIO()
71  
-        compile_messages(out, locale=self.LOCALE)
  60
+        call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO())
72 61
         with translation.override(self.LOCALE):
73 62
             t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
74 63
             rendered = t.render(Context({}))

1 note on commit c3b56c7

Jannis Leidel
Owner
jezdez commented on c3b56c7 May 27, 2012

YES!

Please sign in to comment.
Something went wrong with that request. Please try again.