tests/test-manifest.py
author Gregory Szorc <gregory.szorc@gmail.com>
Fri, 19 May 2017 20:10:50 -0700
changeset 32392 36d3559c69a6
parent 32279 68c43a416585
child 32533 d68f3d6bc214
permissions -rw-r--r--
revlog: tweak wording and logic for flags validation First, the logic around the if..elif..elif was subtly wrong and sub-optimal because all branches would be tested as long as the revlog was valid. This patch changes things so it behaves like a switch statement over the revlog version. While I was here, I also tweaked error strings to make them consistent and to read better.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28929
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     1
from __future__ import absolute_import
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
28929
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     3
import binascii
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     4
import itertools
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
import silenttestrunner
28929
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     6
import unittest
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
28929
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     8
from mercurial import (
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
     9
    manifest as manifestmod,
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
    10
    match as matchmod,
b9ed5a88710c tests: make test-manifest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27637
diff changeset
    11
)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
24569
5491248e148a test-manifest: create constant for empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24549
diff changeset
    13
EMTPY_MANIFEST = ''
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    14
EMTPY_MANIFEST_V2 = '\0\n'
24569
5491248e148a test-manifest: create constant for empty manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 24549
diff changeset
    15
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
HASH_1 = '1' * 40
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
    17
BIN_HASH_1 = binascii.unhexlify(HASH_1)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
HASH_2 = 'f' * 40
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
    19
BIN_HASH_2 = binascii.unhexlify(HASH_2)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
HASH_3 = '1234567890abcdef0987654321deadbeef0fcafe'
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
    21
BIN_HASH_3 = binascii.unhexlify(HASH_3)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
A_SHORT_MANIFEST = (
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
    'bar/baz/qux.py\0%(hash2)s%(flag2)s\n'
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
    'foo\0%(hash1)s%(flag1)s\n'
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
    ) % {'hash1': HASH_1,
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
         'flag1': '',
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
         'hash2': HASH_2,
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
         'flag2': 'l',
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
         }
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    31
# Same data as A_SHORT_MANIFEST
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    32
A_SHORT_MANIFEST_V2 = (
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    33
    '\0\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    34
    '\x00bar/baz/qux.py\0%(flag2)s\n%(hash2)s\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    35
    '\x00foo\0%(flag1)s\n%(hash1)s\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    36
    ) % {'hash1': BIN_HASH_1,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    37
         'flag1': '',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    38
         'hash2': BIN_HASH_2,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    39
         'flag2': 'l',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    40
         }
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    41
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    42
# Same data as A_SHORT_MANIFEST
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    43
A_METADATA_MANIFEST = (
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    44
    '\0foo\0bar\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    45
    '\x00bar/baz/qux.py\0%(flag2)s\0foo\0bar\n%(hash2)s\n' # flag and metadata
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    46
    '\x00foo\0%(flag1)s\0foo\n%(hash1)s\n' # no flag, but metadata
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    47
    ) % {'hash1': BIN_HASH_1,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    48
         'flag1': '',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    49
         'hash2': BIN_HASH_2,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    50
         'flag2': 'l',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    51
         }
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    52
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    53
A_STEM_COMPRESSED_MANIFEST = (
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    54
    '\0\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    55
    '\x00bar/baz/qux.py\0%(flag2)s\n%(hash2)s\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    56
    '\x04qux/foo.py\0%(flag1)s\n%(hash1)s\n' # simple case of 4 stem chars
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    57
    '\x0az.py\0%(flag1)s\n%(hash1)s\n' # tricky newline = 10 stem characters
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    58
    '\x00%(verylongdir)sx/x\0\n%(hash1)s\n'
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    59
    '\xffx/y\0\n%(hash2)s\n' # more than 255 stem chars
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    60
    ) % {'hash1': BIN_HASH_1,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    61
         'flag1': '',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    62
         'hash2': BIN_HASH_2,
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    63
         'flag2': 'l',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    64
         'verylongdir': 255 * 'x',
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    65
         }
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
    66
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    67
A_DEEPER_MANIFEST = (
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    68
    'a/b/c/bar.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    69
    'a/b/c/bar.txt\0%(hash1)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    70
    'a/b/c/foo.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    71
    'a/b/c/foo.txt\0%(hash2)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    72
    'a/b/d/baz.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    73
    'a/b/d/qux.py\0%(hash1)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    74
    'a/b/d/ten.txt\0%(hash3)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    75
    'a/b/dog.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    76
    'a/b/fish.py\0%(hash2)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    77
    'a/c/london.py\0%(hash3)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    78
    'a/c/paper.txt\0%(hash2)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    79
    'a/c/paris.py\0%(hash2)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    80
    'a/d/apple.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    81
    'a/d/pizza.py\0%(hash3)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    82
    'a/green.py\0%(hash1)s%(flag2)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    83
    'a/purple.py\0%(hash2)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    84
    'app.py\0%(hash3)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    85
    'readme.txt\0%(hash2)s%(flag1)s\n'
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    86
    ) % {'hash1': HASH_1,
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    87
         'flag1': '',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    88
         'hash2': HASH_2,
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    89
         'flag2': 'l',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    90
         'hash3': HASH_3,
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    91
         }
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
    92
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
HUGE_MANIFEST_ENTRIES = 200001
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    94
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    95
A_HUGE_MANIFEST = ''.join(sorted(
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    96
    'file%d\0%s%s\n' % (i, h, f) for i, h, f in
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    97
    itertools.izip(xrange(200001),
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    98
                   itertools.cycle((HASH_1, HASH_2)),
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
                   itertools.cycle(('', 'x', 'l')))))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   100
24655
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   101
class basemanifesttests(object):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   102
    def parsemanifest(self, text):
24655
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   103
        raise NotImplementedError('parsemanifest not implemented by test case')
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   104
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
    def assertIn(self, thing, container, msg=None):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   106
        # assertIn new in 2.7, use it if available, otherwise polyfill
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
        sup = getattr(unittest.TestCase, 'assertIn', False)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
        if sup:
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
            return sup(self, thing, container, msg=msg)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   110
        if not msg:
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   111
            msg = 'Expected %r in %r' % (thing, container)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   112
        self.assert_(thing in container, msg)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   113
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   114
    def testEmptyManifest(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   115
        m = self.parsemanifest(EMTPY_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
        self.assertEqual(0, len(m))
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   117
        self.assertEqual([], list(m))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   119
    def testEmptyManifestv2(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   120
        m = self.parsemanifest(EMTPY_MANIFEST_V2)
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   121
        self.assertEqual(0, len(m))
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   122
        self.assertEqual([], list(m))
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   123
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   124
    def testManifest(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   125
        m = self.parsemanifest(A_SHORT_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   126
        self.assertEqual(['bar/baz/qux.py', 'foo'], list(m))
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   127
        self.assertEqual(BIN_HASH_2, m['bar/baz/qux.py'])
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   128
        self.assertEqual('l', m.flags('bar/baz/qux.py'))
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   129
        self.assertEqual(BIN_HASH_1, m['foo'])
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   130
        self.assertEqual('', m.flags('foo'))
32279
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   131
        with self.assertRaises(KeyError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   132
            m['wat']
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   133
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   134
    def testParseManifestV2(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   135
        m1 = self.parsemanifest(A_SHORT_MANIFEST)
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   136
        m2 = self.parsemanifest(A_SHORT_MANIFEST_V2)
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   137
        # Should have same content as A_SHORT_MANIFEST
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   138
        self.assertEqual(m1.text(), m2.text())
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   139
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   140
    def testParseManifestMetadata(self):
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   141
        # Metadata is for future-proofing and should be accepted but ignored
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   142
        m = self.parsemanifest(A_METADATA_MANIFEST)
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   143
        self.assertEqual(A_SHORT_MANIFEST, m.text())
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   144
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   145
    def testParseManifestStemCompression(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   146
        m = self.parsemanifest(A_STEM_COMPRESSED_MANIFEST)
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   147
        self.assertIn('bar/baz/qux.py', m)
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   148
        self.assertIn('bar/qux/foo.py', m)
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   149
        self.assertIn('bar/qux/foz.py', m)
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   150
        self.assertIn(256 * 'x' + '/x', m)
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   151
        self.assertIn(256 * 'x' + '/y', m)
24573
701d3554de0e manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24572
diff changeset
   152
        self.assertEqual(A_STEM_COMPRESSED_MANIFEST, m.text(usemanifestv2=True))
701d3554de0e manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24572
diff changeset
   153
701d3554de0e manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24572
diff changeset
   154
    def testTextV2(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   155
        m1 = self.parsemanifest(A_SHORT_MANIFEST)
24573
701d3554de0e manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24572
diff changeset
   156
        v2text = m1.text(usemanifestv2=True)
701d3554de0e manifestv2: add support for writing new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24572
diff changeset
   157
        self.assertEqual(A_SHORT_MANIFEST_V2, v2text)
24572
b83679eb5f86 manifestv2: add support for reading new manifest format
Martin von Zweigbergk <martinvonz@google.com>
parents: 24570
diff changeset
   158
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   159
    def testSetItem(self):
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   160
        want = BIN_HASH_1
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   161
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   162
        m = self.parsemanifest(EMTPY_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   163
        m['a'] = want
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   164
        self.assertIn('a', m)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   165
        self.assertEqual(want, m['a'])
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   166
        self.assertEqual('a\0' + HASH_1 + '\n', m.text())
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   167
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   168
        m = self.parsemanifest(A_SHORT_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   169
        m['a'] = want
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   170
        self.assertEqual(want, m['a'])
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   171
        self.assertEqual('a\0' + HASH_1 + '\n' + A_SHORT_MANIFEST,
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   172
                         m.text())
24465
bb8e2b1a0803 test-manifest.py: separate out test for double-free after copy()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24298
diff changeset
   173
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   174
    def testSetFlag(self):
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   175
        want = 'x'
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   176
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   177
        m = self.parsemanifest(EMTPY_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   178
        # first add a file; a file-less flag makes no sense
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   179
        m['a'] = BIN_HASH_1
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   180
        m.setflag('a', want)
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   181
        self.assertEqual(want, m.flags('a'))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   182
        self.assertEqual('a\0' + HASH_1 + want + '\n', m.text())
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   183
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   184
        m = self.parsemanifest(A_SHORT_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   185
        # first add a file; a file-less flag makes no sense
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   186
        m['a'] = BIN_HASH_1
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   187
        m.setflag('a', want)
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   188
        self.assertEqual(want, m.flags('a'))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   189
        self.assertEqual('a\0' + HASH_1 + want + '\n' + A_SHORT_MANIFEST,
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   190
                         m.text())
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   191
24465
bb8e2b1a0803 test-manifest.py: separate out test for double-free after copy()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24298
diff changeset
   192
    def testCopy(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   193
        m = self.parsemanifest(A_SHORT_MANIFEST)
27637
b502138f5faa cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents: 25660
diff changeset
   194
        m['a'] = BIN_HASH_1
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
        m2 = m.copy()
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
        del m
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
        del m2 # make sure we don't double free() anything
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   199
    def testCompaction(self):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   200
        unhex = binascii.unhexlify
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   201
        h1, h2 = unhex(HASH_1), unhex(HASH_2)
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   202
        m = self.parsemanifest(A_SHORT_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   203
        m['alpha'] = h1
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   204
        m['beta'] = h2
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   205
        del m['foo']
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   206
        want = 'alpha\0%s\nbar/baz/qux.py\0%sl\nbeta\0%s\n' % (
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   207
            HASH_1, HASH_2, HASH_2)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   208
        self.assertEqual(want, m.text())
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   209
        self.assertEqual(3, len(m))
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   210
        self.assertEqual(['alpha', 'bar/baz/qux.py', 'beta'], list(m))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   211
        self.assertEqual(h1, m['alpha'])
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   212
        self.assertEqual(h2, m['bar/baz/qux.py'])
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   213
        self.assertEqual(h2, m['beta'])
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   214
        self.assertEqual('', m.flags('alpha'))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   215
        self.assertEqual('l', m.flags('bar/baz/qux.py'))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   216
        self.assertEqual('', m.flags('beta'))
32279
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   217
        with self.assertRaises(KeyError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   218
            m['foo']
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   219
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   220
    def testSetGetNodeSuffix(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   221
        clean = self.parsemanifest(A_SHORT_MANIFEST)
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   222
        m = self.parsemanifest(A_SHORT_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   223
        h = m['foo']
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   224
        f = m.flags('foo')
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   225
        want = h + 'a'
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   226
        # Merge code wants to set 21-byte fake hashes at times
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   227
        m['foo'] = want
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   228
        self.assertEqual(want, m['foo'])
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   229
        self.assertEqual([('bar/baz/qux.py', BIN_HASH_2),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   230
                          ('foo', BIN_HASH_1 + 'a')],
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   231
                         list(m.iteritems()))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   232
        # Sometimes it even tries a 22-byte fake hash, but we can
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   233
        # return 21 and it'll work out
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   234
        m['foo'] = want + '+'
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   235
        self.assertEqual(want, m['foo'])
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   236
        # make sure the suffix survives a copy
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   237
        match = matchmod.match('', '', ['re:foo'])
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   238
        m2 = m.matches(match)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   239
        self.assertEqual(want, m2['foo'])
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   240
        self.assertEqual(1, len(m2))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   241
        m2 = m.copy()
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   242
        self.assertEqual(want, m2['foo'])
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   243
        # suffix with iteration
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   244
        self.assertEqual([('bar/baz/qux.py', BIN_HASH_2),
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   245
                          ('foo', want)],
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   246
                         list(m.iteritems()))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   247
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   248
        # shows up in diff
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   249
        self.assertEqual({'foo': ((want, f), (h, ''))}, m.diff(clean))
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   250
        self.assertEqual({'foo': ((h, ''), (want, f))}, clean.diff(m))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   251
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   252
    def testMatchException(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   253
        m = self.parsemanifest(A_SHORT_MANIFEST)
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   254
        match = matchmod.match('', '', ['re:.*'])
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   255
        def filt(path):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   256
            if path == 'foo':
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   257
                assert False
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   258
            return True
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   259
        match.matchfn = filt
32279
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   260
        with self.assertRaises(AssertionError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   261
            m.matches(match)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   262
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   263
    def testRemoveItem(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   264
        m = self.parsemanifest(A_SHORT_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   265
        del m['foo']
32279
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   266
        with self.assertRaises(KeyError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31876
diff changeset
   267
            m['foo']
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
        self.assertEqual(1, len(m))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   269
        self.assertEqual(1, len(list(m)))
24228
542c891274b2 lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
   270
        # now restore and make sure everything works right
24466
f310ca66a704 test-manifest.py: rewrite tests in terms of manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents: 24465
diff changeset
   271
        m['foo'] = 'a' * 20
24228
542c891274b2 lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
   272
        self.assertEqual(2, len(m))
542c891274b2 lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents: 24225
diff changeset
   273
        self.assertEqual(2, len(list(m)))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   274
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   275
    def testManifestDiff(self):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   276
        MISSING = (None, '')
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   277
        addl = 'z-only-in-left\0' + HASH_1 + '\n'
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   278
        addr = 'z-only-in-right\0' + HASH_2 + 'x\n'
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   279
        left = self.parsemanifest(
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   280
            A_SHORT_MANIFEST.replace(HASH_1, HASH_3 + 'x') + addl)
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   281
        right = self.parsemanifest(A_SHORT_MANIFEST + addr)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   282
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   283
            'foo': ((BIN_HASH_3, 'x'),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   284
                    (BIN_HASH_1, '')),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   285
            'z-only-in-left': ((BIN_HASH_1, ''), MISSING),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   286
            'z-only-in-right': (MISSING, (BIN_HASH_2, 'x')),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   287
            }
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   288
        self.assertEqual(want, left.diff(right))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   289
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   290
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   291
            'bar/baz/qux.py': (MISSING, (BIN_HASH_2, 'l')),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   292
            'foo': (MISSING, (BIN_HASH_3, 'x')),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   293
            'z-only-in-left': (MISSING, (BIN_HASH_1, '')),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   294
            }
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   295
        self.assertEqual(want, self.parsemanifest(EMTPY_MANIFEST).diff(left))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   296
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   297
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   298
            'bar/baz/qux.py': ((BIN_HASH_2, 'l'), MISSING),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   299
            'foo': ((BIN_HASH_3, 'x'), MISSING),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   300
            'z-only-in-left': ((BIN_HASH_1, ''), MISSING),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   301
            }
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   302
        self.assertEqual(want, left.diff(self.parsemanifest(EMTPY_MANIFEST)))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   303
        copy = right.copy()
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   304
        del copy['z-only-in-right']
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   305
        del right['foo']
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   306
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   307
            'foo': (MISSING, (BIN_HASH_1, '')),
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   308
            'z-only-in-right': ((BIN_HASH_2, 'x'), MISSING),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
            }
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   310
        self.assertEqual(want, right.diff(copy))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   311
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   312
        short = self.parsemanifest(A_SHORT_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
        pruned = short.copy()
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   314
        del pruned['foo']
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   315
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   316
            'foo': ((BIN_HASH_1, ''), MISSING),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   317
            }
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   318
        self.assertEqual(want, short.diff(pruned))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   319
        want = {
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   320
            'foo': (MISSING, (BIN_HASH_1, '')),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   321
            }
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   322
        self.assertEqual(want, pruned.diff(short))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   323
        want = {
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   324
            'bar/baz/qux.py': None,
24570
487245cbf1ab test-manifest: extract constants for binary hashes
Martin von Zweigbergk <martinvonz@google.com>
parents: 24569
diff changeset
   325
            'foo': (MISSING, (BIN_HASH_1, '')),
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
            }
31255
959ebff3505a manifest: add match argument to diff and filesnotin
Durham Goode <durham@fb.com>
parents: 28929
diff changeset
   327
        self.assertEqual(want, pruned.diff(short, clean=True))
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   328
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   329
    def testReversedLines(self):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   330
        backwards = ''.join(
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   331
            l + '\n' for l in reversed(A_SHORT_MANIFEST.split('\n')) if l)
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   332
        try:
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   333
            self.parsemanifest(backwards)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   334
            self.fail('Should have raised ValueError')
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24656
diff changeset
   335
        except ValueError as v:
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   336
            self.assertIn('Manifest lines not in sorted order.', str(v))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   337
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   338
    def testNoTerminalNewline(self):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   339
        try:
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   340
            self.parsemanifest(A_SHORT_MANIFEST + 'wat')
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   341
            self.fail('Should have raised ValueError')
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24656
diff changeset
   342
        except ValueError as v:
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   343
            self.assertIn('Manifest did not end in a newline.', str(v))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   344
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   345
    def testNoNewLineAtAll(self):
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   346
        try:
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   347
            self.parsemanifest('wat')
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   348
            self.fail('Should have raised ValueError')
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24656
diff changeset
   349
        except ValueError as v:
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   350
            self.assertIn('Manifest did not end in a newline.', str(v))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   351
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   352
    def testHugeManifest(self):
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   353
        m = self.parsemanifest(A_HUGE_MANIFEST)
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   354
        self.assertEqual(HUGE_MANIFEST_ENTRIES, len(m))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   355
        self.assertEqual(len(m), len(list(m)))
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   356
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   357
    def testMatchesMetadata(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   358
        '''Tests matches() for a few specific files to make sure that both
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   359
        the set of files as well as their flags and nodeids are correct in
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   360
        the resulting manifest.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   361
        m = self.parsemanifest(A_HUGE_MANIFEST)
24495
d2a3a2808974 manifest: make manifest.intersectfiles() internal
Drew Gottlieb <drgott@google.com>
parents: 24468
diff changeset
   362
d2a3a2808974 manifest: make manifest.intersectfiles() internal
Drew Gottlieb <drgott@google.com>
parents: 24468
diff changeset
   363
        match = matchmod.match('/', '',
d2a3a2808974 manifest: make manifest.intersectfiles() internal
Drew Gottlieb <drgott@google.com>
parents: 24468
diff changeset
   364
                ['file1', 'file200', 'file300'], exact=True)
d2a3a2808974 manifest: make manifest.intersectfiles() internal
Drew Gottlieb <drgott@google.com>
parents: 24468
diff changeset
   365
        m2 = m.matches(match)
d2a3a2808974 manifest: make manifest.intersectfiles() internal
Drew Gottlieb <drgott@google.com>
parents: 24468
diff changeset
   366
24225
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24214
diff changeset
   367
        w = ('file1\0%sx\n'
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24214
diff changeset
   368
             'file200\0%sl\n'
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24214
diff changeset
   369
             'file300\0%s\n') % (HASH_2, HASH_1, HASH_1)
3e5c4af69808 manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents: 24214
diff changeset
   370
        self.assertEqual(w, m2.text())
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   371
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   372
    def testMatchesNonexistentFile(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   373
        '''Tests matches() for a small set of specific files, including one
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   374
        nonexistent file to make sure in only matches against existing files.
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   375
        '''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   376
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   377
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   378
        match = matchmod.match('/', '',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   379
                ['a/b/c/bar.txt', 'a/b/d/qux.py', 'readme.txt', 'nonexistent'],
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   380
                exact=True)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   381
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   382
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   383
        self.assertEqual(
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   384
                ['a/b/c/bar.txt', 'a/b/d/qux.py', 'readme.txt'],
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   385
                m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   386
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   387
    def testMatchesNonexistentDirectory(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   388
        '''Tests matches() for a relpath match on a directory that doesn't
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   389
        actually exist.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   390
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   391
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   392
        match = matchmod.match('/', '', ['a/f'], default='relpath')
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   393
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   394
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   395
        self.assertEqual([], m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   396
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   397
    def testMatchesExactLarge(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   398
        '''Tests matches() for files matching a large list of exact files.
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   399
        '''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   400
        m = self.parsemanifest(A_HUGE_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   401
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   402
        flist = m.keys()[80:300]
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   403
        match = matchmod.match('/', '', flist, exact=True)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   404
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   405
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   406
        self.assertEqual(flist, m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   407
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   408
    def testMatchesFull(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   409
        '''Tests matches() for what should be a full match.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   410
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   411
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   412
        match = matchmod.match('/', '', [''])
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   413
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   414
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   415
        self.assertEqual(m.keys(), m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   416
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   417
    def testMatchesDirectory(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   418
        '''Tests matches() on a relpath match on a directory, which should
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   419
        match against all files within said directory.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   420
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   421
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   422
        match = matchmod.match('/', '', ['a/b'], default='relpath')
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   423
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   424
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   425
        self.assertEqual([
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   426
            'a/b/c/bar.py', 'a/b/c/bar.txt', 'a/b/c/foo.py', 'a/b/c/foo.txt',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   427
            'a/b/d/baz.py', 'a/b/d/qux.py', 'a/b/d/ten.txt', 'a/b/dog.py',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   428
            'a/b/fish.py'], m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   429
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   430
    def testMatchesExactPath(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   431
        '''Tests matches() on an exact match on a directory, which should
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   432
        result in an empty manifest because you can't perform an exact match
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   433
        against a directory.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   434
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   435
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   436
        match = matchmod.match('/', '', ['a/b'], exact=True)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   437
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   438
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   439
        self.assertEqual([], m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   440
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   441
    def testMatchesCwd(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   442
        '''Tests matches() on a relpath match with the current directory ('.')
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   443
        when not in the root directory.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   444
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   445
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   446
        match = matchmod.match('/', 'a/b', ['.'], default='relpath')
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   447
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   448
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   449
        self.assertEqual([
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   450
            'a/b/c/bar.py', 'a/b/c/bar.txt', 'a/b/c/foo.py', 'a/b/c/foo.txt',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   451
            'a/b/d/baz.py', 'a/b/d/qux.py', 'a/b/d/ten.txt', 'a/b/dog.py',
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   452
            'a/b/fish.py'], m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   453
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   454
    def testMatchesWithPattern(self):
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   455
        '''Tests matches() for files matching a pattern that reside
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   456
        deeper than the specified directory.'''
24654
9d6db63ccf00 test-manifest: move parsemanifest() to be a testmanifest class method
Drew Gottlieb <drgott@google.com>
parents: 24573
diff changeset
   457
        m = self.parsemanifest(A_DEEPER_MANIFEST)
24549
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   458
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   459
        match = matchmod.match('/', '', ['a/b/*/*.txt'])
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   460
        m2 = m.matches(match)
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   461
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   462
        self.assertEqual(
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   463
                ['a/b/c/bar.txt', 'a/b/c/foo.txt', 'a/b/d/ten.txt'],
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   464
                m2.keys())
bcf0de51326e manifest: add some tests for manifest.matches()
Drew Gottlieb <drgott@google.com>
parents: 24495
diff changeset
   465
24655
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   466
class testmanifestdict(unittest.TestCase, basemanifesttests):
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   467
    def parsemanifest(self, text):
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   468
        return manifestmod.manifestdict(text)
528ace39c85c test-manifest: make manifesttest a base class that is extended
Drew Gottlieb <drgott@google.com>
parents: 24654
diff changeset
   469
24656
29c238e4a58a test-manifest: add some test coverage for treemanifest
Drew Gottlieb <drgott@google.com>
parents: 24655
diff changeset
   470
class testtreemanifest(unittest.TestCase, basemanifesttests):
29c238e4a58a test-manifest: add some test coverage for treemanifest
Drew Gottlieb <drgott@google.com>
parents: 24655
diff changeset
   471
    def parsemanifest(self, text):
29c238e4a58a test-manifest: add some test coverage for treemanifest
Drew Gottlieb <drgott@google.com>
parents: 24655
diff changeset
   472
        return manifestmod.treemanifest('', text)
29c238e4a58a test-manifest: add some test coverage for treemanifest
Drew Gottlieb <drgott@google.com>
parents: 24655
diff changeset
   473
31876
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   474
    def testWalkSubtrees(self):
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   475
        m = self.parsemanifest(A_DEEPER_MANIFEST)
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   476
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   477
        dirs = [s._dir for s in m.walksubtrees()]
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   478
        self.assertEqual(
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   479
            sorted(['', 'a/', 'a/c/', 'a/d/', 'a/b/', 'a/b/c/', 'a/b/d/']),
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   480
            sorted(dirs)
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   481
        )
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   482
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   483
        match = matchmod.match('/', '', ['path:a/b/'])
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   484
        dirs = [s._dir for s in m.walksubtrees(matcher=match)]
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   485
        self.assertEqual(
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   486
            sorted(['a/b/', 'a/b/c/', 'a/b/d/']),
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   487
            sorted(dirs)
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   488
        )
94c1d3c1aea2 treemanifest: add walksubtrees api
Durham Goode <durham@fb.com>
parents: 31255
diff changeset
   489
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   490
if __name__ == '__main__':
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff changeset
   491
    silenttestrunner.main(__name__)