Skip to content

Commit

Permalink
Changed FilePathField tests to use it's own directory with test files.
Browse files Browse the repository at this point in the history
In previous version it used /django/forms/ which was fragile - for some
users .pyc files were not generated and this tests failed.
  • Loading branch information
honzakral committed Jun 3, 2012
1 parent 71d9a2a commit a89034a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions tests/regressiontests/forms/tests/fields.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -985,12 +985,11 @@ def test_filepathfield_4(self):
self.assertTrue(got[0].endswith(exp[0])) self.assertTrue(got[0].endswith(exp[0]))


def test_filepathfield_folders(self): def test_filepathfield_folders(self):
path = forms.__file__ path = os.path.dirname(__file__) + '/filepath_test_files/'
path = os.path.dirname(path) + '/'
f = FilePathField(path=path, allow_folders=True, allow_files=False) f = FilePathField(path=path, allow_folders=True, allow_files=False)
f.choices.sort() f.choices.sort()
expected = [ 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)): for exp, got in zip(expected, fix_os_paths(f.choices)):
self.assertEqual(exp[1], got[1]) self.assertEqual(exp[1], got[1])
Expand All @@ -999,23 +998,15 @@ def test_filepathfield_folders(self):
f = FilePathField(path=path, allow_folders=True, allow_files=True) f = FilePathField(path=path, allow_folders=True, allow_files=True)
f.choices.sort() f.choices.sort()
expected = [ expected = [
('/django/forms/__init__.py', '__init__.py'), ('/tests/regressiontests/forms/tests/filepath_test_files/.dot-file', '.dot-file'),
('/django/forms/__init__.pyc', '__init__.pyc'), ('/tests/regressiontests/forms/tests/filepath_test_files/directory', 'directory'),
('/django/forms/extras', 'extras'), ('/tests/regressiontests/forms/tests/filepath_test_files/fake-image.jpg', 'fake-image.jpg'),
('/django/forms/fields.py', 'fields.py'), ('/tests/regressiontests/forms/tests/filepath_test_files/real-text-file.txt', 'real-text-file.txt'),
('/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')
] ]
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.assertEqual(exp[1], got[1])
self.assertTrue(got[0].endswith(exp[0])) self.assertTrue(got[0].endswith(exp[0]))


Expand Down
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.

0 comments on commit a89034a

Please sign in to comment.