Mercurial > hgrepos > Python > libs > ConfigMix
diff tests/test.py @ 550:79db28e879f8
Provide a C-implementation of configmix.config.quote() also: fast_quote
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 02 Jan 2022 02:04:07 +0100 |
| parents | 491413368c7c |
| children | 39e5d07d8dbc |
line wrap: on
line diff
--- a/tests/test.py Sun Jan 02 01:00:10 2022 +0100 +++ b/tests/test.py Sun Jan 02 02:04:07 2022 +0100 @@ -1774,23 +1774,35 @@ class _TParserMixin: def test_quote_and_unquote_empty(self): - e = configmix.quote(u"") + e = self.quote(u"") self.assertEqual(u"", e) self.assertEqual(u"", self.unquote(e)) def test_quoting_and_unquoting_are_inverse(self): for c in u"""%.:#|"'{}[]""": - qc = configmix.quote(c) + qc = self.quote(c) self.assertTrue(qc.startswith(u"%x") and len(qc) == 4) self.assertEqual(c, self.unquote(qc)) + def test_quoting_and_unquoting_are_inverse_all(self): + c = u"""%.:#|"'{}[]""" + qc = self.quote(c) + self.assertEqual(len(c)*4, len(qc)) + self.assertEqual(c, self.unquote(qc)) + def test_quoting_and_unquoting_are_identical(self): # other characters for c in configmix.config._QUOTE_SAFE: - qc = configmix.quote(c) + qc = self.quote(c) self.assertEqual(c, qc) self.assertEqual(c, self.unquote(qc)) + def test_quoting_and_unquoting_are_identical_all(self): + # other characters + qc = self.quote(configmix.config._QUOTE_SAFE) + self.assertEqual(configmix.config._QUOTE_SAFE, qc) + self.assertEqual(configmix.config._QUOTE_SAFE, self.unquote(qc)) + def test_unquote_unimax(self): self.assertEqual(u"\U00019001", self.unquote(u"%U00019001")) self.assertEqual(u"X\U00019AF1Z", self.unquote(u"X%U00019aF1Z")) @@ -1896,6 +1908,7 @@ def setUp(self): self.unquote = configmix.config.py_unquote + self.quote = configmix.config.py_quote self.pathstr2path = configmix.config.py_pathstr2path self.split_ns = configmix.config._py_split_ns @@ -1905,12 +1918,25 @@ self.split_ns, 1) + def test_quote_wrong_type(self): + self.assertRaises( + AttributeError, # no .lstrip + self.quote, + 1) + + def test_unquote_wrong_type(self): + self.assertRaises( + TypeError, # argument of type "int" is not iterable + self.unquote, + 1) + if configmix.config.fast_unquote is not None: class T10FastParser(_TParserMixin, unittest.TestCase): def setUp(self): self.unquote = configmix.config.fast_unquote + self.quote = configmix.config.fast_quote self.pathstr2path = configmix.config.fast_pathstr2path self.split_ns = configmix.config._fast_split_ns @@ -1920,6 +1946,18 @@ self.split_ns, b":") + def test_quote_wrong_type(self): + self.assertRaises( + TypeError, + self.quote, + b":") + + def test_unquote_wrong_type(self): + self.assertRaises( + TypeError, + self.unquote, + b":") + if __name__ == "__main__": unittest.main()
