Description
The current unittests fail on windows, when using the default test command:
python manage.py test --no-input
Cause
The following is the failing test: pydis_site.apps.content.tests.test_views.test_get_context_data_breadcrumbs
|
def test_get_context_data_breadcrumbs(self): |
|
"""The method should return correct breadcrumbs.""" |
|
request = self.factory.get("/category/subcategory/with_metadata") |
|
self.ViewClass.setup(request) |
|
self.ViewClass.dispatch(request, location="category/subcategory/with_metadata") |
|
|
|
context = self.ViewClass.get_context_data() |
|
self.assertEquals( |
|
context["breadcrumb_items"], |
|
[ |
|
{"name": PARSED_CATEGORY_INFO["title"], "path": "."}, |
|
{"name": PARSED_CATEGORY_INFO["title"], "path": "category"}, |
|
{"name": PARSED_CATEGORY_INFO["title"], "path": "category/subcategory"}, |
|
] |
|
) |
The reason is in the following line:
|
{"name": PARSED_CATEGORY_INFO["title"], "path": "category/subcategory"}, |
Now, context["breadcrumb_items"][2]["path"] would normally produce category/subcategory. Those who have worked with paths before know where this is going, but since we are doing a blind comparison on the string values of paths, we end up with the following assertion error:
category/subcategory != category\\subcategory
(left is expected, right is the output on windows)
Solution
These sort of things wouldn't cause actual problems while running, because windows, and python, can both gracefully handle either format.
One option when it comes to fixing this test, is to pass both ends through a Path call, resulting in:
context = self.ViewClass.get_context_data()
context["breadcrumb_items"][2]["path"] = Path(context["breadcrumb_items"][2]["path"])
self.assertEquals(
context["breadcrumb_items"],
[
{"name": PARSED_CATEGORY_INFO["title"], "path": "."},
{"name": PARSED_CATEGORY_INFO["title"], "path": "category"},
{"name": PARSED_CATEGORY_INFO["title"], "path": Path("category/subcategory")},
]
)
This should work because we will be comparing two paths objects, instead of pure strings.
This isn't a real solution though, generally speaking. It will solve the problem here, but this sort of thing can slip in at any time. This specific bug appears to have existed since Kosa did the rewrite, but I'm willing to bet it has existed for much longer. Either way, it's been in for quite a while.
Now, one thing we could do is add windows to our testing CI. It's not a fun process from my experience, but I can't think of a better solution right now. Alternatively, we just completely ignore windows, though as a windows user, I have to try and advocate against that :).
I'm open to hearing other solutions.
Description
The current unittests fail on windows, when using the default test command:
Cause
The following is the failing test:
pydis_site.apps.content.tests.test_views.test_get_context_data_breadcrumbssite/pydis_site/apps/content/tests/test_views.py
Lines 163 to 177 in 512bd17
The reason is in the following line:
site/pydis_site/apps/content/tests/test_views.py
Line 175 in 512bd17
Now,
context["breadcrumb_items"][2]["path"]would normally producecategory/subcategory. Those who have worked with paths before know where this is going, but since we are doing a blind comparison on the string values of paths, we end up with the following assertion error:category/subcategory != category\\subcategory(left is expected, right is the output on windows)
Solution
These sort of things wouldn't cause actual problems while running, because windows, and python, can both gracefully handle either format.
One option when it comes to fixing this test, is to pass both ends through a Path call, resulting in:
This should work because we will be comparing two paths objects, instead of pure strings.
This isn't a real solution though, generally speaking. It will solve the problem here, but this sort of thing can slip in at any time. This specific bug appears to have existed since Kosa did the rewrite, but I'm willing to bet it has existed for much longer. Either way, it's been in for quite a while.
Now, one thing we could do is add windows to our testing CI. It's not a fun process from my experience, but I can't think of a better solution right now. Alternatively, we just completely ignore windows, though as a windows user, I have to try and advocate against that :).
I'm open to hearing other solutions.