test_DirectEntry.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # coding=utf-8
  2. from direct.gui.DirectEntry import DirectEntry
  3. import sys
  4. def test_entry_get():
  5. entry = DirectEntry()
  6. assert isinstance(entry.get(), str)
  7. def test_entry_auto_capitalize():
  8. # Now we can generate the DirectEntry component itself. In normal use, we
  9. # would pass "autoCapitalize=1" to DirectEntry's constructor in order for
  10. # DirectEntry._autoCapitalize() to be called upon typing into the entry
  11. # GUI, however in the case of this unit test where there is no GUI to type
  12. # into, we don't need to bother doing that; we're just calling the function
  13. # ourselves anyway.
  14. entry = DirectEntry()
  15. # Test DirectEntry._autoCapitalize(). The intended behavior would be that
  16. # the first letter of each word in the entry would be capitalized, so that
  17. # is what we will check for:
  18. entry.set('auto capitalize test')
  19. entry._autoCapitalize()
  20. assert entry.get() == 'Auto Capitalize Test'
  21. # Test DirectEntry._autoCapitalize() with a unicode object this time.
  22. entry.set(u'àütò çapítalízè ţèsţ')
  23. assert entry.get() == u'àütò çapítalízè ţèsţ'
  24. entry._autoCapitalize()
  25. assert entry.get() == u'Àütò Çapítalízè Ţèsţ'
  26. # Also test it with a UTF-8 encoded byte string in Python 2.
  27. if sys.version_info < (3, 0):
  28. entry.set(u'àütò çapítalízè ţèsţ'.encode('utf-8'))
  29. assert entry.get() == u'àütò çapítalízè ţèsţ'
  30. entry._autoCapitalize()
  31. assert entry.get() == u'Àütò Çapítalízè Ţèsţ'