Opened 3 years ago
Closed 3 years ago
#32959 closed Cleanup/optimization (fixed)
URLValidator test cases can be defined in a Python module
Reported by: | Chris Jerdonek | Owned by: | Bal Krishna Jha |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
I noticed that the URLValidator tests have a number of test cases defined in separate text files (valid_urls.txt
and invalid_urls.txt
): https://github.com/django/django/tree/012f38f9594b35743e9ab231757b7b62db638323/tests/validators
However, it seems like it would be more maintainable if these test cases were defined in a Python module (e.g. the same tests.py
file containing the test code). One reason is that there aren't actually that many test cases to warrant a separate file. Another is that having them as part of a Python module would permit them to be annotated with code comments. Currently, none of the test cases have any comments elaborating on what they're testing, and having them in a text file precludes that possibility. Finally, if there are any concerns about mistranscribing from the text files to a Python module, the transcription could be done with a Python script to eliminate the possibility of transcription errors.
Change History (8)
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
comment:3 by , 3 years ago
That's a good thought and would indeed be better. But since the two files are only 76 lines and 87 lines, I think we could safely keep them next to / nearer the actual tests. In Django's code, it's not uncommon to find single functions that run to that length (and whole modules a great deal longer than that), so I don't see much problem in having test data of that length. (If we needed to split anything, splitting the URLValidator
tests off from DecimalValidator
, email tests, etc. into its own test_urls.py
might be a more natural division.)
comment:4 by , 3 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
OK, let's move them directly to the TEST_DATA
in tests/validators/tests.py
.
comment:5 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
We could also keep them in
.py
modules, e.g.valid_urls.py
,invalid_urls.py
:What do you think?