Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made a couple of changes for readability and correctness in loaddata.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17055 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bebbc9e4a537f45bfd24a902d223ad96d743a524 1 parent 0a1a9b7
Ramiro Morales authored October 29, 2011
12  django/core/management/commands/loaddata.py
@@ -62,7 +62,7 @@ def handle(self, *fixture_labels, **options):
62 62
         fixture_object_count = 0
63 63
         models = set()
64 64
 
65  
-        humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute path'
  65
+        humanize = lambda dirname: "'%s'" % dirname if dirname else 'absolute path'
66 66
 
67 67
         # Get a cursor (even though we don't need one yet). This has
68 68
         # the side effect of initializing the test database (if
@@ -160,6 +160,11 @@ def read(self):
160 160
                     open_method = compression_types[compression_format]
161 161
                     try:
162 162
                         fixture = open_method(full_path, 'r')
  163
+                    except IOError:
  164
+                        if verbosity >= 2:
  165
+                            self.stdout.write("No %s fixture '%s' in %s.\n" % \
  166
+                                (format, fixture_name, humanize(fixture_dir)))
  167
+                    else:
163 168
                         if label_found:
164 169
                             fixture.close()
165 170
                             self.stderr.write(self.style.ERROR("Multiple fixtures named '%s' in %s. Aborting.\n" %
@@ -232,11 +237,6 @@ def read(self):
232 237
                                     transaction.leave_transaction_management(using=using)
233 238
                                 return
234 239
 
235  
-                    except Exception, e:
236  
-                        if verbosity >= 2:
237  
-                            self.stdout.write("No %s fixture '%s' in %s.\n" % \
238  
-                                (format, fixture_name, humanize(fixture_dir)))
239  
-
240 240
         # If we found even one object in a fixture, we need to reset the
241 241
         # database sequences.
242 242
         if loaded_object_count > 0:
12  tests/regressiontests/fixtures_regress/tests.py
@@ -405,6 +405,18 @@ def test_loaddata_no_fixture_specified(self):
405 405
             stderr.getvalue(), 'No database fixture specified. Please provide the path of at least one fixture in the command line.\n'
406 406
         )
407 407
 
  408
+    def test_loaddata_not_existant_fixture_file(self):
  409
+        stdout_output = StringIO()
  410
+        management.call_command(
  411
+            'loaddata',
  412
+            'this_fixture_doesnt_exist',
  413
+            verbosity=2,
  414
+            commit=False,
  415
+            stdout=stdout_output,
  416
+        )
  417
+        self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
  418
+            stdout_output.getvalue())
  419
+
408 420
 
409 421
 class NaturalKeyFixtureTests(TestCase):
410 422
 

0 notes on commit bebbc9e

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