Patchwork [2,of,6] patch.pathtransform: add doctests

login
register
mail settings
Submitter Siddharth Agarwal
Date March 7, 2015, 8:44 a.m.
Message ID <cb5ad173db606136e121.1425717884@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7920/
State Accepted
Headers show

Comments

Siddharth Agarwal - March 7, 2015, 8:44 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1425707320 28800
#      Fri Mar 06 21:48:40 2015 -0800
# Node ID cb5ad173db606136e1215dc25f164c45e92a11fd
# Parent  7a5ce9323351fa75a3488efa31b91358d81d8f89
patch.pathtransform: add doctests

In upcoming patches we're going to make this function more complex, so add some
unit tests for it.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1088,6 +1088,22 @@ 
     return s[:i]
 
 def pathtransform(path, strip):
+    '''turn a path from a patch into a path suitable for the repository
+
+    Returns (stripped components, path in repository).
+
+    >>> pathtransform('a/b/c', 0)
+    ('', 'a/b/c')
+    >>> pathtransform('   a/b/c   ', 0)
+    ('', '   a/b/c')
+    >>> pathtransform('   a/b/c   ', 2)
+    ('a/b/', 'c')
+    >>> pathtransform('   a//b/c   ', 2)
+    ('a//b/', 'c')
+    >>> pathtransform('a/b/c', 3)
+    Traceback (most recent call last):
+    PatchError: unable to strip away 1 of 3 dirs from a/b/c
+    '''
     pathlen = len(path)
     i = 0
     if strip == 0:
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -19,6 +19,7 @@ 
 testmod('mercurial.hgweb.hgwebdir_mod')
 testmod('mercurial.match')
 testmod('mercurial.minirst')
+testmod('mercurial.patch')
 testmod('mercurial.pathutil')
 testmod('mercurial.revset')
 testmod('mercurial.store')