| 45 | |
| 46 | class TestCollationObject(unittest.TestCase): |
| 47 | def test_constructor(self): |
| 48 | self.assertRaises(TypeError, Collation, locale=42) |
| 49 | # Fill in a locale to test the other options. |
| 50 | _Collation = functools.partial(Collation, "en_US") |
| 51 | # No error. |
| 52 | _Collation(caseFirst=CollationCaseFirst.UPPER) |
| 53 | self.assertRaises(TypeError, _Collation, caseLevel="true") |
| 54 | self.assertRaises(ValueError, _Collation, strength="six") |
| 55 | self.assertRaises(TypeError, _Collation, numericOrdering="true") |
| 56 | self.assertRaises(TypeError, _Collation, alternate=5) |
| 57 | self.assertRaises(TypeError, _Collation, maxVariable=2) |
| 58 | self.assertRaises(TypeError, _Collation, normalization="false") |
| 59 | self.assertRaises(TypeError, _Collation, backwards="true") |
| 60 | |
| 61 | # No errors. |
| 62 | Collation("en_US", future_option="bar", another_option=42) |
| 63 | collation = Collation( |
| 64 | "en_US", |
| 65 | caseLevel=True, |
| 66 | caseFirst=CollationCaseFirst.UPPER, |
| 67 | strength=CollationStrength.QUATERNARY, |
| 68 | numericOrdering=True, |
| 69 | alternate=CollationAlternate.SHIFTED, |
| 70 | maxVariable=CollationMaxVariable.SPACE, |
| 71 | normalization=True, |
| 72 | backwards=True, |
| 73 | ) |
| 74 | |
| 75 | self.assertEqual( |
| 76 | { |
| 77 | "locale": "en_US", |
| 78 | "caseLevel": True, |
| 79 | "caseFirst": "upper", |
| 80 | "strength": 4, |
| 81 | "numericOrdering": True, |
| 82 | "alternate": "shifted", |
| 83 | "maxVariable": "space", |
| 84 | "normalization": True, |
| 85 | "backwards": True, |
| 86 | }, |
| 87 | collation.document, |
| 88 | ) |
| 89 | |
| 90 | self.assertEqual( |
| 91 | {"locale": "en_US", "backwards": True}, Collation("en_US", backwards=True).document |
| 92 | ) |
| 93 | |
| 94 | |
| 95 | class TestCollation(IntegrationTest): |