comparison tests/test.py @ 543:491413368c7c

Added also a fast C-implementation of configmix.config._split_ns
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 01 Jan 2022 18:01:32 +0100
parents f71d34dda19f
children 79db28e879f8
comparison
equal deleted inserted replaced
542:f71d34dda19f 543:491413368c7c
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 = configmix.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 = configmix.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))
1872 1872
1873 def test_split_unquote(self): 1873 def test_split_unquote(self):
1874 p = self.pathstr2path(u"a%x2Eb.c%u002Ed.e%U0000002Ef") 1874 p = self.pathstr2path(u"a%x2Eb.c%u002Ed.e%U0000002Ef")
1875 self.assertEqual((u"a.b", u"c.d", u"e.f"), p) 1875 self.assertEqual((u"a.b", u"c.d", u"e.f"), p)
1876 1876
1877 def test_split_ns_empty(self):
1878 self.assertEqual((None, u""), self.split_ns(u""))
1879
1880 def test_split_ns_empty_parts(self):
1881 self.assertEqual((u"", u""), self.split_ns(u":"))
1882
1883 def test_split_ns_no_ns(self):
1884 self.assertEqual((None, u"the-varname"), self.split_ns(u"the-varname"))
1885
1886 def test_split_ns_non_quoted(self):
1887 self.assertEqual(
1888 (u"the-ns", "the-rest:with:colons|filter1|filter2"),
1889 self.split_ns(u"the-ns:the-rest:with:colons|filter1|filter2"))
1890
1891 def test_split_ns_quoting(self):
1892 self.assertEqual((u":", u"%x3a"), self.split_ns(u"%x3a:%x3a"))
1893
1877 1894
1878 class T09Parser(_TParserMixin, unittest.TestCase): 1895 class T09Parser(_TParserMixin, unittest.TestCase):
1879 1896
1880 def setUp(self): 1897 def setUp(self):
1881 self.unquote = configmix.config.py_unquote 1898 self.unquote = configmix.config.py_unquote
1882 self.pathstr2path = configmix.config.py_pathstr2path 1899 self.pathstr2path = configmix.config.py_pathstr2path
1900 self.split_ns = configmix.config._py_split_ns
1901
1902 def test_split_ns_wrong_type(self):
1903 self.assertRaises(
1904 AttributeError, # no .partition
1905 self.split_ns,
1906 1)
1883 1907
1884 1908
1885 if configmix.config.fast_unquote is not None: 1909 if configmix.config.fast_unquote is not None:
1886 class T10FastParser(_TParserMixin, unittest.TestCase): 1910 class T10FastParser(_TParserMixin, unittest.TestCase):
1887 1911
1888 def setUp(self): 1912 def setUp(self):
1889 self.unquote = configmix.config.fast_unquote 1913 self.unquote = configmix.config.fast_unquote
1890 self.pathstr2path = configmix.config.fast_pathstr2path 1914 self.pathstr2path = configmix.config.fast_pathstr2path
1915 self.split_ns = configmix.config._fast_split_ns
1916
1917 def test_split_ns_wrong_type(self):
1918 self.assertRaises(
1919 TypeError,
1920 self.split_ns,
1921 b":")
1891 1922
1892 1923
1893 if __name__ == "__main__": 1924 if __name__ == "__main__":
1894 unittest.main() 1925 unittest.main()