From ff188c1dcaa20d83954e61ebc2a0e0c71ff86886 Mon Sep 17 00:00:00 2001 From: John Cote Date: Wed, 14 Aug 2019 13:19:18 +0200 Subject: [PATCH] tests: Add unit test for DirectEntry._autoCapitalize() Closes #628 Co-authored-by: rdb --- tests/gui/test_DirectEntry.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/gui/test_DirectEntry.py diff --git a/tests/gui/test_DirectEntry.py b/tests/gui/test_DirectEntry.py new file mode 100644 index 0000000000..4e462ebdbc --- /dev/null +++ b/tests/gui/test_DirectEntry.py @@ -0,0 +1,38 @@ +# coding=utf-8 +from direct.gui.DirectEntry import DirectEntry +import sys + + +def test_entry_get(): + entry = DirectEntry() + assert isinstance(entry.get(), str) + + +def test_entry_auto_capitalize(): + # Now we can generate the DirectEntry component itself. In normal use, we + # would pass "autoCapitalize=1" to DirectEntry's constructor in order for + # DirectEntry._autoCapitalize() to be called upon typing into the entry + # GUI, however in the case of this unit test where there is no GUI to type + # into, we don't need to bother doing that; we're just calling the function + # ourselves anyway. + entry = DirectEntry() + + # Test DirectEntry._autoCapitalize(). The intended behavior would be that + # the first letter of each word in the entry would be capitalized, so that + # is what we will check for: + entry.set('auto capitalize test') + entry._autoCapitalize() + assert entry.get() == 'Auto Capitalize Test' + + # Test DirectEntry._autoCapitalize() with a unicode object this time. + entry.set(u'àütò çapítalízè ţèsţ') + assert entry.get() == u'àütò çapítalízè ţèsţ' + entry._autoCapitalize() + assert entry.get() == u'Àütò Çapítalízè Ţèsţ' + + # Also test it with a UTF-8 encoded byte string in Python 2. + if sys.version_info < (3, 0): + entry.set(u'àütò çapítalízè ţèsţ'.encode('utf-8')) + assert entry.get() == u'àütò çapítalízè ţèsţ' + entry._autoCapitalize() + assert entry.get() == u'Àütò Çapítalízè Ţèsţ'