Scott Baker | d194097 | 2017-05-01 15:45:32 -0700 | [diff] [blame^] | 1 | import exceptions |
| 2 | import shutil |
| 3 | import sys |
| 4 | import unittest |
| 5 | |
| 6 | from twisted.internet import reactor |
| 7 | from xosapi import xos_grpc_client |
| 8 | |
| 9 | exitStatus = -1 |
| 10 | |
| 11 | # TODO: See if there's a way to stub this out using a fake xos_grpc_client |
| 12 | # instead of the real one. |
| 13 | |
| 14 | class TestORM(unittest.TestCase): |
| 15 | def test_repr_name(self): |
| 16 | s = xos_grpc_client.coreapi.Slice(name="foo") |
| 17 | self.assertNotEqual(s, None) |
| 18 | self.assertEqual(repr(s), "<Slice: foo>") |
| 19 | |
| 20 | def test_str_name(self): |
| 21 | s = xos_grpc_client.coreapi.Slice(name="foo") |
| 22 | self.assertNotEqual(s, None) |
| 23 | self.assertEqual(str(s), "foo") |
| 24 | |
| 25 | def test_dumpstr_name(self): |
| 26 | s = xos_grpc_client.coreapi.Slice(name="foo") |
| 27 | self.assertNotEqual(s, None) |
| 28 | self.assertEqual(s.dumpstr(), 'name: "foo"\n') |
| 29 | |
| 30 | def test_repr_noname(self): |
| 31 | s = xos_grpc_client.coreapi.Slice() |
| 32 | self.assertNotEqual(s, None) |
| 33 | self.assertEqual(repr(s), "<Slice: id-0>") |
| 34 | |
| 35 | def test_str_noname(self): |
| 36 | s = xos_grpc_client.coreapi.Slice() |
| 37 | self.assertNotEqual(s, None) |
| 38 | self.assertEqual(str(s), "Slice-0") |
| 39 | |
| 40 | def test_dumpstr_noname(self): |
| 41 | s = xos_grpc_client.coreapi.Slice() |
| 42 | self.assertNotEqual(s, None) |
| 43 | self.assertEqual(s.dumpstr(), '') |
| 44 | |
| 45 | def test_callback(): |
| 46 | try: |
| 47 | unittest.main() |
| 48 | except exceptions.SystemExit, e: |
| 49 | global exitStatus |
| 50 | exitStatus = e.code |
| 51 | |
| 52 | xos_grpc_client.start_api_parseargs(test_callback) |
| 53 | |
| 54 | sys.exit(exitStatus) |