tests/test-dirs.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 01 Mar 2023 02:38:20 +0100
branchstable
changeset 49700 379a78001d8e
parent 48966 6000f5b25c9b
permissions -rw-r--r--
dirstate: set identity whenever we read the dirstate's v2 docket The docket can be loaded outside of a full read (for exemple when pre-fetching parents), so the current code would read/set the identity after loading the data, opening a race condition: A0: first process docket is read B0: other process appends new data to the dirstate (and changes the docket) A1: first process sets the identity (based on pre-B content, but with post-B identity) A1: first process loads the dirstatemap from the data file A1: first process does not detect the race and overwrites the update from B.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
import unittest
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
import silenttestrunner
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43542
diff changeset
     5
from mercurial import pathutil
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
class dirstests(unittest.TestCase):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
    def testdirs(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
        for case, want in [
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
            (b'a/a/a', [b'a', b'a/a', b'']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
            (b'alpha/beta/gamma', [b'', b'alpha', b'alpha/beta']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
        ]:
48043
627cd8f33db0 rust: Remove support for passing a dict to the Rust pathutil.dirs()
Simon Sapin <simon.sapin@octobus.net>
parents: 43571
diff changeset
    14
            d = pathutil.dirs([])
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
            d.addpath(case)
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
            self.assertEqual(sorted(d), sorted(want))
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
    def testinvalid(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
        with self.assertRaises(ValueError):
48043
627cd8f33db0 rust: Remove support for passing a dict to the Rust pathutil.dirs()
Simon Sapin <simon.sapin@octobus.net>
parents: 43571
diff changeset
    20
            d = pathutil.dirs([])
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
            d.addpath(b'a//b')
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
if __name__ == '__main__':
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
    silenttestrunner.main(__name__)