2 from clang
.cindex
import Config
4 if "CLANG_LIBRARY_PATH" in os
.environ
:
5 Config
.set_library_path(os
.environ
["CLANG_LIBRARY_PATH"])
7 from clang
.cindex
import TokenKind
12 class TestTokenKind(unittest
.TestCase
):
13 def test_constructor(self
):
14 """Ensure TokenKind constructor works as expected."""
16 t
= TokenKind(5, "foo")
18 self
.assertEqual(t
.value
, 5)
19 self
.assertEqual(t
.name
, "foo")
21 def test_bad_register(self
):
22 """Ensure a duplicate value is rejected for registration."""
24 with self
.assertRaises(ValueError):
25 TokenKind
.register(2, "foo")
27 def test_unknown_value(self
):
28 """Ensure trying to fetch an unknown value raises."""
30 with self
.assertRaises(ValueError):
31 TokenKind
.from_value(-1)
33 def test_registration(self
):
34 """Ensure that items registered appear as class attributes."""
35 self
.assertTrue(hasattr(TokenKind
, "LITERAL"))
36 literal
= TokenKind
.LITERAL
38 self
.assertIsInstance(literal
, TokenKind
)
40 def test_from_value(self
):
41 """Ensure registered values can be obtained from from_value()."""
42 t
= TokenKind
.from_value(3)
43 self
.assertIsInstance(t
, TokenKind
)
44 self
.assertEqual(t
, TokenKind
.LITERAL
)
47 """Ensure repr() works."""
49 r
= repr(TokenKind
.LITERAL
)
50 self
.assertEqual(r
, "TokenKind.LITERAL")