Author: ramiro
Date: 2011-10-29 15:32:28 -0700 (Sat, 29 Oct 2011)
New Revision: 17055

Modified:
   django/trunk/django/core/management/commands/loaddata.py
   django/trunk/tests/regressiontests/fixtures_regress/tests.py
Log:
Made a couple of changes for readability and correctness in loaddata.

Modified: django/trunk/django/core/management/commands/loaddata.py
===================================================================
--- django/trunk/django/core/management/commands/loaddata.py    2011-10-29 
15:28:44 UTC (rev 17054)
+++ django/trunk/django/core/management/commands/loaddata.py    2011-10-29 
22:32:28 UTC (rev 17055)
@@ -62,7 +62,7 @@
         fixture_object_count = 0
         models = set()
 
-        humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute 
path'
+        humanize = lambda dirname: "'%s'" % dirname if dirname else 'absolute 
path'
 
         # Get a cursor (even though we don't need one yet). This has
         # the side effect of initializing the test database (if
@@ -160,6 +160,11 @@
                     open_method = compression_types[compression_format]
                     try:
                         fixture = open_method(full_path, 'r')
+                    except IOError:
+                        if verbosity >= 2:
+                            self.stdout.write("No %s fixture '%s' in %s.\n" % \
+                                (format, fixture_name, humanize(fixture_dir)))
+                    else:
                         if label_found:
                             fixture.close()
                             self.stderr.write(self.style.ERROR("Multiple 
fixtures named '%s' in %s. Aborting.\n" %
@@ -232,11 +237,6 @@
                                     
transaction.leave_transaction_management(using=using)
                                 return
 
-                    except Exception, e:
-                        if verbosity >= 2:
-                            self.stdout.write("No %s fixture '%s' in %s.\n" % \
-                                (format, fixture_name, humanize(fixture_dir)))
-
         # If we found even one object in a fixture, we need to reset the
         # database sequences.
         if loaded_object_count > 0:

Modified: django/trunk/tests/regressiontests/fixtures_regress/tests.py
===================================================================
--- django/trunk/tests/regressiontests/fixtures_regress/tests.py        
2011-10-29 15:28:44 UTC (rev 17054)
+++ django/trunk/tests/regressiontests/fixtures_regress/tests.py        
2011-10-29 22:32:28 UTC (rev 17055)
@@ -405,7 +405,19 @@
             stderr.getvalue(), 'No database fixture specified. Please provide 
the path of at least one fixture in the command line.\n'
         )
 
+    def test_loaddata_not_existant_fixture_file(self):
+        stdout_output = StringIO()
+        management.call_command(
+            'loaddata',
+            'this_fixture_doesnt_exist',
+            verbosity=2,
+            commit=False,
+            stdout=stdout_output,
+        )
+        self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
+            stdout_output.getvalue())
 
+
 class NaturalKeyFixtureTests(TestCase):
 
     def test_nk_deserialize(self):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to