Source code

Revision control

Other Tools

Test Info:

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at
from __future__ import absolute_import
from __future__ import unicode_literals
import unittest
from io import StringIO
import pytest
from mozunit import main
from six import string_types
from pathlib import Path
from mach.base import CommandContext
from mach.registrar import Registrar
@pytest.mark.usefixtures("get_mach", "run_mach")
class TestDispatcher(unittest.TestCase):
"""Tests dispatch related code"""
def get_parser(self, config=None):
mach = self.get_mach(Path(""))
for provider in Registrar.settings_providers:
if config:
if isinstance(config, string_types):
config = StringIO(config)
context = CommandContext(cwd="", settings=mach.settings)
return mach.get_argument_parser(context)
def test_command_aliases(self):
config = """
foo = cmd_foo
bar = cmd_bar
baz = cmd_bar --baz
cmd_bar = cmd_bar --baz
parser = self.get_parser(config=config)
args = parser.parse_args(["foo"])
self.assertEquals(args.command, "cmd_foo")
def assert_bar_baz(argv):
args = parser.parse_args(argv)
self.assertEquals(args.command, "cmd_bar")
# The following should all result in |cmd_bar --baz|
assert_bar_baz(["bar", "--baz"])
if __name__ == "__main__":