Ticket #6868: 6868_filepathfield_tests.diff
File 6868_filepathfield_tests.diff, 2.8 KB (added by , 17 years ago) |
---|
-
tests/regressiontests/forms/fields.py
1135 1135 1136 1136 # FilePathField ############################################################### 1137 1137 1138 >>> def fix_os_paths(x): 1139 ... if isinstance(x, basestring): 1140 ... return x.replace('\\', '/') 1141 ... elif isinstance(x, tuple): 1142 ... return tuple(fix_os_paths(list(x))) 1143 ... elif isinstance(x, list): 1144 ... return [fix_os_paths(y) for y in x] 1145 ... else: 1146 ... return x 1147 ... 1138 1148 >>> import os 1139 1149 >>> from django import newforms as forms 1140 1150 >>> path = forms.__file__ 1141 1151 >>> path = os.path.dirname(path) + '/' 1142 >>> path1152 >>> fix_os_paths(path) 1143 1153 '.../django/newforms/' 1144 1154 >>> f = forms.FilePathField(path=path) 1145 1155 >>> f.choices.sort() 1146 >>> f .choices1156 >>> fix_os_paths(f.choices) 1147 1157 [('.../django/newforms/__init__.py', '__init__.py'), ('.../django/newforms/__init__.pyc', '__init__.pyc'), ('.../django/newforms/fields.py', 'fields.py'), ('.../django/newforms/fields.pyc', 'fields.pyc'), ('.../django/newforms/forms.py', 'forms.py'), ('.../django/newforms/forms.pyc', 'forms.pyc'), ('.../django/newforms/models.py', 'models.py'), ('.../django/newforms/models.pyc', 'models.pyc'), ('.../django/newforms/util.py', 'util.py'), ('.../django/newforms/util.pyc', 'util.pyc'), ('.../django/newforms/widgets.py', 'widgets.py'), ('.../django/newforms/widgets.pyc', 'widgets.pyc')] 1148 1158 >>> f.clean('fields.py') 1149 1159 Traceback (most recent call last): 1150 1160 ... 1151 1161 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] 1152 >>> f .clean(path + 'fields.py')1162 >>> fix_os_paths(f.clean(path + 'fields.py')) 1153 1163 u'.../django/newforms/fields.py' 1154 1164 >>> f = forms.FilePathField(path=path, match='^.*?\.py$') 1155 1165 >>> f.choices.sort() 1156 >>> f .choices1166 >>> fix_os_paths(f.choices) 1157 1167 [('.../django/newforms/__init__.py', '__init__.py'), ('.../django/newforms/fields.py', 'fields.py'), ('.../django/newforms/forms.py', 'forms.py'), ('.../django/newforms/models.py', 'models.py'), ('.../django/newforms/util.py', 'util.py'), ('.../django/newforms/widgets.py', 'widgets.py')] 1158 1168 >>> f = forms.FilePathField(path=path, recursive=True, match='^.*?\.py$') 1159 1169 >>> f.choices.sort() 1160 >>> f .choices1170 >>> fix_os_paths(f.choices) 1161 1171 [('.../django/newforms/__init__.py', '__init__.py'), ('.../django/newforms/extras/__init__.py', 'extras/__init__.py'), ('.../django/newforms/extras/widgets.py', 'extras/widgets.py'), ('.../django/newforms/fields.py', 'fields.py'), ('.../django/newforms/forms.py', 'forms.py'), ('.../django/newforms/models.py', 'models.py'), ('.../django/newforms/util.py', 'util.py'), ('.../django/newforms/widgets.py', 'widgets.py')] 1162 1172 1163 1173 # SplitDateTimeField ##########################################################