testConversionErrors.py 790 B

123456789101112131415161718192021222324252627282930313233
  1. import unittest
  2. import win32com.client
  3. import win32com.test.util
  4. import win32com.server.util
  5. class Tester:
  6. _public_methods_ = [ 'TestValue' ]
  7. def TestValue(self, v):
  8. pass
  9. def test_ob():
  10. return win32com.client.Dispatch(win32com.server.util.wrap(Tester()))
  11. class TestException(Exception):
  12. pass
  13. # The object we try and pass - pywin32 will call __float__ as a last resort.
  14. class BadConversions:
  15. def __float__(self):
  16. raise TestException()
  17. class TestCase(win32com.test.util.TestCase):
  18. def test_float(self):
  19. try:
  20. test_ob().TestValue(BadConversions())
  21. raise Exception("Should not have worked")
  22. except Exception as e:
  23. assert isinstance(e, TestException)
  24. if __name__=='__main__':
  25. unittest.main()