tests/test-admin-commands.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 23 Oct 2023 14:27:07 +0200
changeset 51090 de6a8cc24de3
parent 50989 752c5a5b73c6
permissions -rw-r--r--
revlog: move the splitting-inline-revlog logic inside the inner object This is another large IO block that we need to move within the inner object if we want's it to be self sufficient.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50989
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     1
# Test admin commands
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     2
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     3
import functools
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     4
import unittest
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     5
from mercurial.i18n import _
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     6
from mercurial import error, ui as uimod
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     7
from mercurial import registrar
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     8
from mercurial.admin import verify
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     9
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    10
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    11
class TestAdminVerifyFindChecks(unittest.TestCase):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    12
    def __init__(self, *args, **kwargs):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    13
        super().__init__(*args, **kwargs)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    14
        self.ui = uimod.ui.load()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    15
        self.repo = b"fake-repo"
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    16
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    17
        def cleanup_table(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    18
            self.table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    19
            self.alias_table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    20
            self.pyramid = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    21
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    22
        self.addCleanup(cleanup_table, self)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    23
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    24
    def setUp(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    25
        self.table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    26
        self.alias_table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    27
        self.pyramid = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    28
        check = registrar.verify_check(self.table, self.alias_table)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    29
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    30
        # mock some fake check method for tests purpose
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    31
        @check(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    32
            b"test.dummy",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    33
            alias=b"dummy",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    34
            options=[],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    35
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    36
        def check_dummy(ui, repo, **options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
            return options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    38
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    39
        @check(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    40
            b"test.fake",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    41
            alias=b"fake",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    42
            options=[
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    43
                (b'a', False, _(b'a boolean value (default: False)')),
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    44
                (b'b', True, _(b'a boolean value (default: True)')),
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    45
                (b'c', [], _(b'a list')),
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    46
            ],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    47
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    48
        def check_fake(ui, repo, **options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    49
            return options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    50
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    51
        # alias in the middle of a hierarchy
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    52
        check(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    53
            b"test.noop",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    54
            alias=b"noop",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    55
            options=[],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
        )(verify.noop_func)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    57
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
        @check(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    59
            b"test.noop.deeper",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
            alias=b"deeper",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    61
            options=[
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    62
                (b'y', True, _(b'a boolean value (default: True)')),
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    63
                (b'z', [], _(b'a list')),
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    64
            ],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    65
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    66
        def check_noop_deeper(ui, repo, **options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    67
            return options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    68
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    69
    # args wrapper utilities
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    70
    def find_checks(self, name):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    71
        return verify.find_checks(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    72
            name=name,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    73
            table=self.table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    74
            alias_table=self.alias_table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    75
            full_pyramid=self.pyramid,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    76
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    77
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    78
    def pass_options(self, checks, options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    79
        return verify.pass_options(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    80
            self.ui,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    81
            checks,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    82
            options,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    83
            table=self.table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    84
            alias_table=self.alias_table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    85
            full_pyramid=self.pyramid,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    86
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    87
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    88
    def get_checks(self, names, options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    89
        return verify.get_checks(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    90
            self.repo,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    91
            self.ui,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    92
            names=names,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    93
            options=options,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    94
            table=self.table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    95
            alias_table=self.alias_table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    96
            full_pyramid=self.pyramid,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    97
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    98
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    99
    # tests find_checks
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   100
    def test_find_checks_empty_name(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   101
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   102
            self.find_checks(name=b"")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   103
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   104
    def test_find_checks_wrong_name(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   105
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   106
            self.find_checks(name=b"unknown")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   107
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   108
    def test_find_checks_dummy(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   109
        name = b"test.dummy"
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   110
        found = self.find_checks(name=name)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   111
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   112
        self.assertIn(name, found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   113
        meth = found[name]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   114
        self.assertTrue(callable(meth))
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   115
        self.assertEqual(len(meth.options), 0)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   116
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   117
    def test_find_checks_fake(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   118
        name = b"test.fake"
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   119
        found = self.find_checks(name=name)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   120
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   121
        self.assertIn(name, found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   122
        meth = found[name]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   123
        self.assertTrue(callable(meth))
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
        self.assertEqual(len(meth.options), 3)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   125
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   126
    def test_find_checks_noop(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   127
        name = b"test.noop.deeper"
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   128
        found = self.find_checks(name=name)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   129
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   130
        self.assertIn(name, found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   131
        meth = found[name]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   132
        self.assertTrue(callable(meth))
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   133
        self.assertEqual(len(meth.options), 2)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   134
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   135
    def test_find_checks_from_aliases(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   136
        found = self.find_checks(name=b"dummy")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   137
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   138
        self.assertIn(b"test.dummy", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   139
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   140
        found = self.find_checks(name=b"fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   141
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   142
        self.assertIn(b"test.fake", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   143
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
        found = self.find_checks(name=b"deeper")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   145
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   146
        self.assertIn(b"test.noop.deeper", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   147
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   148
    def test_find_checks_from_root(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   149
        found = self.find_checks(name=b"test")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   150
        self.assertEqual(len(found), 3)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   151
        self.assertIn(b"test.dummy", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   152
        self.assertIn(b"test.fake", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   153
        self.assertIn(b"test.noop.deeper", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   154
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   155
    def test_find_checks_from_intermediate(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   156
        found = self.find_checks(name=b"test.noop")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   157
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   158
        self.assertIn(b"test.noop.deeper", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   159
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   160
    def test_find_checks_from_parent_dot_name(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   161
        found = self.find_checks(name=b"noop.deeper")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   162
        self.assertEqual(len(found), 1)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   163
        self.assertIn(b"test.noop.deeper", found)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   164
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   165
    # tests pass_options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   166
    def test_pass_options_no_checks_no_options(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   167
        checks = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   168
        options = []
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   169
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   170
        with self.assertRaises(error.Error):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   171
            self.pass_options(checks=checks, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   172
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   173
    def test_pass_options_fake_empty_options(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   174
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   175
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   176
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   177
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   178
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   179
        options = []
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   180
        # should end with default options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   181
        expected_options = {"a": False, "b": True, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   182
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   183
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   184
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   185
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   186
    def test_pass_options_fake_non_existing_options(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   187
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   188
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   189
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   190
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   191
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   192
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   193
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   194
            options = [b"test.fake:boom=yes"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   195
            self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   196
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   197
    def test_pass_options_fake_unrelated_options(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   198
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   199
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   200
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   201
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   202
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   203
        options = [b"test.noop.deeper:y=yes"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   204
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   205
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   206
            self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   207
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   208
    def test_pass_options_fake_set_option(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   209
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   210
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   211
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   212
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   213
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   214
        options = [b"test.fake:a=yes"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   215
        expected_options = {"a": True, "b": True, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   216
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   217
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   218
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   219
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   220
    def test_pass_options_fake_set_option_with_alias(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   221
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   222
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   223
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   224
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   225
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   226
        options = [b"fake:a=yes"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   227
        expected_options = {"a": True, "b": True, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   228
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   229
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   230
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   231
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   232
    def test_pass_options_fake_set_all_option(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   233
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   234
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   235
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   236
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   237
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   238
        options = [b"test.fake:a=yes", b"test.fake:b=no", b"test.fake:c=0,1,2"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   239
        expected_options = {"a": True, "b": False, "c": [b"0", b"1", b"2"]}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   240
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   241
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   242
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   243
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   244
    def test_pass_options_fake_set_all_option_plus_unexisting(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   245
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   246
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   247
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   248
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   249
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   250
        options = [
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   251
            b"test.fake:a=yes",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   252
            b"test.fake:b=no",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   253
            b"test.fake:c=0,1,2",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   254
            b"test.fake:d=0",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   255
        ]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   256
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   257
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   258
            self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   259
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   260
    def test_pass_options_fake_duplicate_option(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   262
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   263
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   264
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   265
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   266
        options = [
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   267
            b"test.fake:a=yes",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   268
            b"test.fake:a=no",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   269
        ]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   270
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   271
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   272
            self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   273
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   274
    def test_pass_options_fake_set_malformed_option(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   275
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   276
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   277
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   278
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   279
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   280
        options = [
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   281
            b"test.fake:ayes",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   282
            b"test.fake:b==no",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   283
            b"test.fake=",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   284
            b"test.fake:",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   285
            b"test.fa=ke:d=0",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   286
            b"test.fa=ke:d=0",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   287
        ]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   288
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   289
        for opt in options:
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   290
            with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   291
                self.pass_options(checks=funcs, options=[opt])
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   292
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   293
    def test_pass_options_types(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   294
        checks = self.find_checks(name=b"test.fake")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   295
        funcs = {
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   296
            n: functools.partial(f, self.ui, self.repo)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   297
            for n, f in checks.items()
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   298
        }
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   299
        # boolean, yes/no
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   300
        options = [b"test.fake:a=yes", b"test.fake:b=no"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   301
        expected_options = {"a": True, "b": False, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   302
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   303
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   304
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   305
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   306
        # boolean, 0/1
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   307
        options = [b"test.fake:a=1", b"test.fake:b=0"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   308
        expected_options = {"a": True, "b": False, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   309
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   310
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   311
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   312
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
        # boolean, true/false
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   314
        options = [b"test.fake:a=true", b"test.fake:b=false"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   315
        expected_options = {"a": True, "b": False, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   316
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   317
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   318
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   319
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   320
        # boolean, wrong type
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   321
        options = [b"test.fake:a=si"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   322
        with self.assertRaises(error.InputError):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   323
            self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   324
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   325
        # lists
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   326
        options = [b"test.fake:c=0,1,2"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   327
        expected_options = {"a": False, "b": True, "c": [b"0", b"1", b"2"]}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   328
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   329
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   330
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   331
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   332
        options = [b"test.fake:c=x,y,z"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   333
        expected_options = {"a": False, "b": True, "c": [b"x", b"y", b"z"]}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   334
        func = self.pass_options(checks=funcs, options=options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   335
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   336
        self.assertDictEqual(func[b"test.fake"].keywords, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   337
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   338
    # tests get_checks
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   339
    def test_get_checks_fake(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   340
        funcs = self.get_checks(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   341
            names=[b"test.fake"], options=[b"test.fake:a=yes"]
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   342
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   343
        options = funcs.get(b"test.fake").keywords
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   344
        expected_options = {"a": True, "b": True, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   345
        self.assertDictEqual(options, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   346
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   347
    def test_get_checks_multiple_mixed_with_defaults(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   348
        funcs = self.get_checks(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   349
            names=[b"test.fake", b"test.noop.deeper", b"test.dummy"],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   350
            options=[
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   351
                b"test.noop.deeper:y=no",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   352
                b"test.noop.deeper:z=-1,0,1",
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   353
            ],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   354
        )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   355
        options = funcs.get(b"test.fake").keywords
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   356
        expected_options = {"a": False, "b": True, "c": []}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   357
        self.assertDictEqual(options, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   358
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   359
        options = funcs.get(b"test.noop.deeper").keywords
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   360
        expected_options = {"y": False, "z": [b"-1", b"0", b"1"]}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   361
        self.assertDictEqual(options, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   362
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   363
        options = funcs.get(b"test.dummy").keywords
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   364
        expected_options = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   365
        self.assertDictEqual(options, expected_options)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   366
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   367
    def test_broken_pyramid(self):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   368
        """Check that we detect pyramids that can't resolve"""
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   369
        table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   370
        alias_table = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   371
        pyramid = {}
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   372
        check = registrar.verify_check(table, alias_table)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   373
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   374
        # Create two checks that clash
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   375
        @check(b"test.wrong.intermediate")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   376
        def check_dummy(ui, repo, **options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   377
            return options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   378
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   379
        @check(b"test.wrong.intermediate.thing")
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   380
        def check_fake(ui, repo, **options):
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   381
            return options
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   382
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   383
        with self.assertRaises(error.ProgrammingError) as e:
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   384
            verify.get_checks(
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   385
                self.repo,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   386
                self.ui,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
                names=[b"test.wrong.intermediate"],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   388
                options=[],
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   389
                table=table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   390
                alias_table=alias_table,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   391
                full_pyramid=pyramid,
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   392
            )
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   393
        assert "`verify.noop_func`" in str(e.exception), str(e.exception)
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   394
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   395
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   396
if __name__ == '__main__':
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   397
    import silenttestrunner
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   398
752c5a5b73c6 admin-command: add verify command
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
    silenttestrunner.main(__name__)