test_DirectEntry.py 1.6 KB

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