j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
97 stars 33 forks source link

test fail issue when packaging on debian #94

Open yuzibo opened 1 year ago

yuzibo commented 1 year ago

hi, I am packaging the tkcalendar into Debian. But I am stuck with one of the test cases that failed. In my understanding, these test cases should be tested under real \$(DISPLAY) env to emulate tkcalendar's usage scenarios. But on Debian buildd env is pure chroot, there is no \$(DISPLAY) env to offer for tkcalendar. Fortunately, I got help from Debian python team to use HOME=/tmp xvfb-run -a dh_auto_test -a to emulate the env.

So the last result here is failed in test_calendar_textvariable. I guess that it is needed with input something, right? sorry, I am not to used tkcalendar before. Any help will be appricated.

I: pybuild base:240: cd /<<PKGBUILDDIR>>/.pybuild/cpython3_3.10/build; python3.10 -m unittest discover -v
test_calendar_buttons_functions (tests.test_calendar.TestCalendar) ... ok
test_calendar_calevents (tests.test_calendar.TestCalendar) ... ok
test_calendar_get_set (tests.test_calendar.TestCalendar) ... ok
test_calendar_init (tests.test_calendar.TestCalendar) ... ok
test_calendar_other_fcts (tests.test_calendar.TestCalendar) ... ok
test_calendar_selection (tests.test_calendar.TestCalendar) ... ok
test_calendar_textvariable (tests.test_calendar.TestCalendar) ... ERROR
test_calendar_virtual_events (tests.test_calendar.TestCalendar) ... ok
test_dateentry_drop_down (tests.test_dateentry.TestDateEntry)
Check whether drop down opens on click. ... ok
test_dateentry_functions (tests.test_dateentry.TestDateEntry) ... ok
test_dateentry_get_set (tests.test_dateentry.TestDateEntry) ... ok
test_dateentry_init (tests.test_dateentry.TestDateEntry) ... ok
test_tooltip (tests.test_tooltip.TestTooltip) ... ok
test_tooltip_config (tests.test_tooltip.TestTooltipWrapper) ... ok
test_tooltipwrapper (tests.test_tooltip.TestTooltipWrapper) ... ok
test_tooltipwrapper_init (tests.test_tooltip.TestTooltipWrapper) ... ok

======================================================================
ERROR: test_calendar_textvariable (tests.test_calendar.TestCalendar)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.10/build/tests/test_calendar.py", line 228, in test_calendar_textvariable
    widget = Calendar(self.window, selectmode='day',
  File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.10/build/tkcalendar/calendar_.py", line 268, in __init__
    self._sel_date = parse_date(self._textvariable.get(), locale)
  File "/usr/lib/python3/dist-packages/babel/dates.py", line 1196, in parse_date
    raise ParseError("No numbers were found in input")
babel.dates.ParseError: No numbers were found in input

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.10/build/tests/test_calendar.py", line 230, in test_calendar_textvariable
    except Calendar.ParseError:
AttributeError: type object 'Calendar' has no attribute 'ParseError'

----------------------------------------------------------------------
Ran 16 tests in 0.278s

FAILED (errors=1)
E: pybuild pybuild:379: test: plugin distutils failed with: exit code=1: cd /<<PKGBUILDDIR>>/.pybuild/cpython3_3.10/build; python3.10 -m unittest discover -v
AceScottie commented 1 year ago

I can offer what the issue is but I do not know how to fix it fully.

The issue is caused by the bind evens being triggered before the StringVar is populated with text. Babel then gets a blank input which it cannot parse.

https://github.com/j4321/tkcalendar/blob/0c6aa7cb4ee1e583bdf0faec62f99f760f192895/tests/test_calendar.py#L226

add another line after this to set a default date value to correct for this error. var.set('01/01/1970')

Use whatever format the date_pattern is set to.

A full fix will require finding if the StringVar has a value set and ignoring/setting it if not (like it currently ignores if not StringVar is passed to the constructor).