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 }
};
"""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):
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'))