Mercurial > hgrepos > Python > libs > ConfigMix
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 549:84657447ab39 | 550:79db28e879f8 |
|---|---|
| 1772 self.assertEqual(u"in the root namespace", jcfg[2]) | 1772 self.assertEqual(u"in the root namespace", jcfg[2]) |
| 1773 | 1773 |
| 1774 | 1774 |
| 1775 class _TParserMixin: | 1775 class _TParserMixin: |
| 1776 def test_quote_and_unquote_empty(self): | 1776 def test_quote_and_unquote_empty(self): |
| 1777 e = configmix.quote(u"") | 1777 e = self.quote(u"") |
| 1778 self.assertEqual(u"", e) | 1778 self.assertEqual(u"", e) |
| 1779 self.assertEqual(u"", self.unquote(e)) | 1779 self.assertEqual(u"", self.unquote(e)) |
| 1780 | 1780 |
| 1781 def test_quoting_and_unquoting_are_inverse(self): | 1781 def test_quoting_and_unquoting_are_inverse(self): |
| 1782 for c in u"""%.:#|"'{}[]""": | 1782 for c in u"""%.:#|"'{}[]""": |
| 1783 qc = configmix.quote(c) | 1783 qc = self.quote(c) |
| 1784 self.assertTrue(qc.startswith(u"%x") and len(qc) == 4) | 1784 self.assertTrue(qc.startswith(u"%x") and len(qc) == 4) |
| 1785 self.assertEqual(c, self.unquote(qc)) | 1785 self.assertEqual(c, self.unquote(qc)) |
| 1786 | |
| 1787 def test_quoting_and_unquoting_are_inverse_all(self): | |
| 1788 c = u"""%.:#|"'{}[]""" | |
| 1789 qc = self.quote(c) | |
| 1790 self.assertEqual(len(c)*4, len(qc)) | |
| 1791 self.assertEqual(c, self.unquote(qc)) | |
| 1786 | 1792 |
| 1787 def test_quoting_and_unquoting_are_identical(self): | 1793 def test_quoting_and_unquoting_are_identical(self): |
| 1788 # other characters | 1794 # other characters |
| 1789 for c in configmix.config._QUOTE_SAFE: | 1795 for c in configmix.config._QUOTE_SAFE: |
| 1790 qc = configmix.quote(c) | 1796 qc = self.quote(c) |
| 1791 self.assertEqual(c, qc) | 1797 self.assertEqual(c, qc) |
| 1792 self.assertEqual(c, self.unquote(qc)) | 1798 self.assertEqual(c, self.unquote(qc)) |
| 1799 | |
| 1800 def test_quoting_and_unquoting_are_identical_all(self): | |
| 1801 # other characters | |
| 1802 qc = self.quote(configmix.config._QUOTE_SAFE) | |
| 1803 self.assertEqual(configmix.config._QUOTE_SAFE, qc) | |
| 1804 self.assertEqual(configmix.config._QUOTE_SAFE, self.unquote(qc)) | |
| 1793 | 1805 |
| 1794 def test_unquote_unimax(self): | 1806 def test_unquote_unimax(self): |
| 1795 self.assertEqual(u"\U00019001", self.unquote(u"%U00019001")) | 1807 self.assertEqual(u"\U00019001", self.unquote(u"%U00019001")) |
| 1796 self.assertEqual(u"X\U00019AF1Z", self.unquote(u"X%U00019aF1Z")) | 1808 self.assertEqual(u"X\U00019AF1Z", self.unquote(u"X%U00019aF1Z")) |
| 1797 | 1809 |
| 1894 | 1906 |
| 1895 class T09Parser(_TParserMixin, unittest.TestCase): | 1907 class T09Parser(_TParserMixin, unittest.TestCase): |
| 1896 | 1908 |
| 1897 def setUp(self): | 1909 def setUp(self): |
| 1898 self.unquote = configmix.config.py_unquote | 1910 self.unquote = configmix.config.py_unquote |
| 1911 self.quote = configmix.config.py_quote | |
| 1899 self.pathstr2path = configmix.config.py_pathstr2path | 1912 self.pathstr2path = configmix.config.py_pathstr2path |
| 1900 self.split_ns = configmix.config._py_split_ns | 1913 self.split_ns = configmix.config._py_split_ns |
| 1901 | 1914 |
| 1902 def test_split_ns_wrong_type(self): | 1915 def test_split_ns_wrong_type(self): |
| 1903 self.assertRaises( | 1916 self.assertRaises( |
| 1904 AttributeError, # no .partition | 1917 AttributeError, # no .partition |
| 1905 self.split_ns, | 1918 self.split_ns, |
| 1906 1) | 1919 1) |
| 1907 | 1920 |
| 1921 def test_quote_wrong_type(self): | |
| 1922 self.assertRaises( | |
| 1923 AttributeError, # no .lstrip | |
| 1924 self.quote, | |
| 1925 1) | |
| 1926 | |
| 1927 def test_unquote_wrong_type(self): | |
| 1928 self.assertRaises( | |
| 1929 TypeError, # argument of type "int" is not iterable | |
| 1930 self.unquote, | |
| 1931 1) | |
| 1932 | |
| 1908 | 1933 |
| 1909 if configmix.config.fast_unquote is not None: | 1934 if configmix.config.fast_unquote is not None: |
| 1910 class T10FastParser(_TParserMixin, unittest.TestCase): | 1935 class T10FastParser(_TParserMixin, unittest.TestCase): |
| 1911 | 1936 |
| 1912 def setUp(self): | 1937 def setUp(self): |
| 1913 self.unquote = configmix.config.fast_unquote | 1938 self.unquote = configmix.config.fast_unquote |
| 1939 self.quote = configmix.config.fast_quote | |
| 1914 self.pathstr2path = configmix.config.fast_pathstr2path | 1940 self.pathstr2path = configmix.config.fast_pathstr2path |
| 1915 self.split_ns = configmix.config._fast_split_ns | 1941 self.split_ns = configmix.config._fast_split_ns |
| 1916 | 1942 |
| 1917 def test_split_ns_wrong_type(self): | 1943 def test_split_ns_wrong_type(self): |
| 1918 self.assertRaises( | 1944 self.assertRaises( |
| 1919 TypeError, | 1945 TypeError, |
| 1920 self.split_ns, | 1946 self.split_ns, |
| 1921 b":") | 1947 b":") |
| 1922 | 1948 |
| 1949 def test_quote_wrong_type(self): | |
| 1950 self.assertRaises( | |
| 1951 TypeError, | |
| 1952 self.quote, | |
| 1953 b":") | |
| 1954 | |
| 1955 def test_unquote_wrong_type(self): | |
| 1956 self.assertRaises( | |
| 1957 TypeError, | |
| 1958 self.unquote, | |
| 1959 b":") | |
| 1960 | |
| 1923 | 1961 |
| 1924 if __name__ == "__main__": | 1962 if __name__ == "__main__": |
| 1925 unittest.main() | 1963 unittest.main() |
