From a89034a2d8c0ca84184d260090d87645cfdc0e7d Mon Sep 17 00:00:00 2001 From: Honza Kral Date: Sun, 3 Jun 2012 22:54:34 +0200 Subject: [PATCH] Changed FilePathField tests to use it's own directory with test files. In previous version it used /django/forms/ which was fragile - for some users .pyc files were not generated and this tests failed. --- tests/regressiontests/forms/tests/fields.py | 29 +++++++------------ .../forms/tests/filepath_test_files/.dot-file | 0 .../tests/filepath_test_files/directory/.keep | 0 .../tests/filepath_test_files/fake-image.jpg | 0 .../filepath_test_files/real-text-file.txt | 0 5 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 tests/regressiontests/forms/tests/filepath_test_files/.dot-file create mode 100644 tests/regressiontests/forms/tests/filepath_test_files/directory/.keep create mode 100644 tests/regressiontests/forms/tests/filepath_test_files/fake-image.jpg create mode 100644 tests/regressiontests/forms/tests/filepath_test_files/real-text-file.txt diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index 9800cfb879..4d442de382 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -985,12 +985,11 @@ class FieldsTests(SimpleTestCase): self.assertTrue(got[0].endswith(exp[0])) def test_filepathfield_folders(self): - path = forms.__file__ - path = os.path.dirname(path) + '/' + path = os.path.dirname(__file__) + '/filepath_test_files/' f = FilePathField(path=path, allow_folders=True, allow_files=False) f.choices.sort() expected = [ - ('/django/forms/extras', 'extras'), + ('/tests/regressiontests/forms/tests/filepath_test_files/directory', 'directory'), ] for exp, got in zip(expected, fix_os_paths(f.choices)): self.assertEqual(exp[1], got[1]) @@ -999,23 +998,15 @@ class FieldsTests(SimpleTestCase): f = FilePathField(path=path, allow_folders=True, allow_files=True) f.choices.sort() expected = [ - ('/django/forms/__init__.py', '__init__.py'), - ('/django/forms/__init__.pyc', '__init__.pyc'), - ('/django/forms/extras', 'extras'), - ('/django/forms/fields.py', 'fields.py'), - ('/django/forms/fields.pyc', 'fields.pyc'), - ('/django/forms/forms.py', 'forms.py'), - ('/django/forms/forms.pyc', 'forms.pyc'), - ('/django/forms/formsets.py', 'formsets.py'), - ('/django/forms/formsets.pyc', 'formsets.pyc'), - ('/django/forms/models.py', 'models.py'), - ('/django/forms/models.pyc', 'models.pyc'), - ('/django/forms/util.py', 'util.py'), - ('/django/forms/util.pyc', 'util.pyc'), - ('/django/forms/widgets.py', 'widgets.py'), - ('/django/forms/widgets.pyc', 'widgets.pyc') + ('/tests/regressiontests/forms/tests/filepath_test_files/.dot-file', '.dot-file'), + ('/tests/regressiontests/forms/tests/filepath_test_files/directory', 'directory'), + ('/tests/regressiontests/forms/tests/filepath_test_files/fake-image.jpg', 'fake-image.jpg'), + ('/tests/regressiontests/forms/tests/filepath_test_files/real-text-file.txt', 'real-text-file.txt'), ] - for exp, got in zip(expected, fix_os_paths(f.choices)): + + actual = fix_os_paths(f.choices) + self.assertEqual(len(expected), len(actual)) + for exp, got in zip(expected, actual): self.assertEqual(exp[1], got[1]) self.assertTrue(got[0].endswith(exp[0])) diff --git a/tests/regressiontests/forms/tests/filepath_test_files/.dot-file b/tests/regressiontests/forms/tests/filepath_test_files/.dot-file new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/forms/tests/filepath_test_files/directory/.keep b/tests/regressiontests/forms/tests/filepath_test_files/directory/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/forms/tests/filepath_test_files/fake-image.jpg b/tests/regressiontests/forms/tests/filepath_test_files/fake-image.jpg new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/forms/tests/filepath_test_files/real-text-file.txt b/tests/regressiontests/forms/tests/filepath_test_files/real-text-file.txt new file mode 100644 index 0000000000..e69de29bb2