-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Issue 778. #779
base: master
Are you sure you want to change the base?
Fix for Issue 778. #779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,6 @@ | ||||||
# 2.36 (2024-10-24) | ||||||
* Fix: Categories with characters incompatible with the current locale opens (#778, Oussama Jarrousse). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# 2.35 (2024-09-22) | ||||||
* Add option to auto-indent text in editor and activate it by default (#561, #562, Allen Benter, Varunjay Varma). | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
# ----------------------------------------------------------------------- | ||||||
|
||||||
import http.client | ||||||
import locale | ||||||
import logging | ||||||
import os.path | ||||||
import re | ||||||
|
@@ -202,3 +203,14 @@ def flush(self): | |||||
def close(self): | ||||||
for stream in self.streams: | ||||||
stream.close() | ||||||
|
||||||
def safe_strxfrm(value): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
Safely apply locale-aware sorting. If locale.strxfrm fails, fall back to default sorting. | ||||||
""" | ||||||
try: | ||||||
return locale.strxfrm(value) | ||||||
except OSError: | ||||||
return value | ||||||
except: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need the bare except? I think it's better to remove it since we have the except for OSError. |
||||||
return value |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from datetime import date | ||
from rednotebook.data import Month, Day # Assuming you have access to these | ||
|
||
from rednotebook.journal import Journal | ||
|
||
@pytest.fixture | ||
def mock_month(): | ||
month = Month(2024, 10) | ||
day1 = Day(month, 1, {"text": "Example text", "Aria": {}}) | ||
day2 = Day(month, 2, {"text": "More example text", "Aria": {}, "Opera":{}, "Étude":{}}) | ||
day3 = Day(month, 3, {"text": "Another text", "Sonata": {}, "Prelude": {}, "Opera": {}, "Concerto":{}}) | ||
day4 = Day(month, 4, {"text": "Regression test for issue 778", "Opera":{}, "المُوَشَّح":{}}) | ||
|
||
month.days[1] = day1 | ||
month.days[2] = day2 | ||
month.days[3] = day3 | ||
month.days[4] = day4 | ||
|
||
yield month | ||
|
||
|
||
def test_categories(mock_month): | ||
# Create an empty journal instance | ||
journal = Journal() | ||
|
||
# Add a month with no days to the journal | ||
journal.months = { (2024, 10): Month(2024, 10) } | ||
|
||
# Ensure that the categories list is empty | ||
assert journal.categories == [], "Expected no categories in an empty journal" | ||
|
||
# Add a month with days to the journal | ||
journal.months = { (2024, 10): mock_month } | ||
|
||
# Assert the categories property returns expected categories sorted alphabetically | ||
expected_categories = ['Aria', 'Concerto', 'Étude', 'Opera', 'Prelude', 'Sonata', 'المُوَشَّح'] | ||
|
||
assert journal.categories == expected_categories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.