Add some tests for path manipulation functions.
authorJelmer Vernooij <jelmer@jelmer.uk>
Wed, 23 May 2018 19:27:59 +0000 (20:27 +0100)
committerJelmer Vernooij <jelmer@jelmer.uk>
Wed, 23 May 2018 19:27:59 +0000 (20:27 +0100)
subvertpy/subr.c
subvertpy/tests/test_subr.py

index 2a2af7b125b959461c682c40f865e3be930fda47..6bf2aa26bd00b8496c09a3849df2745e5c3dbe2d 100644 (file)
@@ -42,9 +42,47 @@ static PyObject *py_uri_canonicalize(PyObject *self, PyObject *args)
     return ret;
 }
 
+static PyObject *py_dirent_canonicalize(PyObject *self, PyObject *args)
+{
+    const char *dirent;
+    PyObject *py_dirent, *ret;
+    apr_pool_t *pool;
+
+    if (!PyArg_ParseTuple(args, "O", &py_dirent))
+        return NULL;
+
+    pool = Pool(NULL);
+    dirent = py_object_to_svn_dirent(py_dirent, pool);
+    ret = PyUnicode_FromString(dirent);
+    apr_pool_destroy(pool);
+
+    return ret;
+}
+
+static PyObject *py_abspath(PyObject *self, PyObject *args)
+{
+    const char *path;
+    PyObject *py_path, *ret;
+    apr_pool_t *pool;
+
+    if (!PyArg_ParseTuple(args, "O", &py_path))
+        return NULL;
+
+    pool = Pool(NULL);
+    path = py_object_to_svn_abspath(py_path, pool);
+    ret = PyUnicode_FromString(path);
+    apr_pool_destroy(pool);
+
+    return ret;
+}
+
 static PyMethodDef subr_methods[] = {
     { "uri_canonicalize", py_uri_canonicalize, METH_VARARGS, "uri_canonicalize(uri) -> uri\n"
         "Canonicalize a URI."},
+    { "dirent_canonicalize", py_dirent_canonicalize, METH_VARARGS, "dirent_canonicalize(dirent) -> dirent\n"
+        "Canonicalize a dirent path."},
+    { "abspath", py_abspath, METH_VARARGS, "abspath(path) -> path\n"
+        "Return the absolute version of a path."},
     { NULL }
 };
 
index b80290f04541f70aa50310b21655446524c83f59..c471e65f2e79fac29b1e53e07faad5f3bdc0d2f3 100644 (file)
 
 """Subversion subr library tests."""
 
+import os
 from unittest import TestCase
 
-from subvertpy.subr import uri_canonicalize
+from subvertpy.subr import (
+    uri_canonicalize,
+    dirent_canonicalize,
+    abspath,
+    )
 
 
 class UriCanonicalizeTests(TestCase):
@@ -32,3 +37,28 @@ class UriCanonicalizeTests(TestCase):
         self.assertEqual(
                 'https://www.example.com/(bla)',
                 uri_canonicalize('https://www.example.com/(bla%29'))
+
+
+class DirentCanonicalizeTests(TestCase):
+
+    def test_canonicalize(self):
+        self.assertEqual(
+                '/foo/bar',
+                dirent_canonicalize('/foo/bar'))
+        self.assertEqual(
+                '/foo/bar',
+                dirent_canonicalize('/foo//bar'))
+
+
+class AbspathTests(TestCase):
+
+    def test_abspath(self):
+        self.assertEqual(
+                '/foo/bar',
+                abspath('/foo//bar'))
+        self.assertEqual(
+                os.path.join(os.getcwd(), 'bar'),
+                abspath('bar'))
+        self.assertEqual(
+                os.path.join(os.getcwd(), 'bar', 'foo'),
+                abspath('bar/foo'))