def register_cli(self):
        """Register the command line interface.

        .. versionadded:: 0.4.0
        """
        # A try/except is being used here rather than suppress so that
        # any ImportErrors raised as a result of registering the
        # commands aren't swallowed.
        try:
            #
            import alembic  # NOQA
        except ImportError:
            # Don't enable migrations.
            pass
        else:
            # Alembic is installed so the CLI should be enabled.
            register_commands('db', (
                branches,
                current,
                downgrade,
                edit,
                generate,
                heads,
                history,
                init,
                merge,
                revision,
                show,
                stamp,
                upgrade,
            ))
Beispiel #2
0
    def register_cli(self):
        """Register the command line interface.

        .. versionadded:: 0.4.0
        """
        # A try/except is being used here rather than suppress so that
        # any ImportErrors raised as a result of registering the
        # commands aren't swallowed.
        try:
            #
            import alembic  # NOQA
        except ImportError:
            # Don't enable migrations.
            pass
        else:
            # Alembic is installed so the CLI should be enabled.
            register_commands('db', (
                branches,
                current,
                downgrade,
                edit,
                generate,
                heads,
                history,
                init,
                merge,
                revision,
                show,
                stamp,
                upgrade,
            ))
Beispiel #3
0
def test_register_commands_keyword_only_conflicts(monkeypatch):
    """Test register_commands with key-only arguments with conflicts."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(*, arg1=1, arg2=2):
        pass

    cli.register_commands('testing', [keyword])

    with pytest.raises(SystemExit):
        cli.parser.parse_args(['testing', 'keyword', '-a', '1'])
Beispiel #4
0
def test_register_commands(monkeypatch):
    """Test register_commands with no arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def simple():
        pass

    cli.register_commands('testing', [simple])

    args = cli.parser.parse_args(['testing', 'simple'])
    assert args
Beispiel #5
0
def test_register_commands(monkeypatch):
    """Test register_commands with no arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def simple():
        pass

    cli.register_commands('testing', [simple])

    args = cli.parser.parse_args(['testing', 'simple'])
    assert args
Beispiel #6
0
def test_register_commands_keyword_only_conflicts(monkeypatch):
    """Test register_commands with key-only arguments with conflicts."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(*, arg1=1, arg2=2):
        pass

    cli.register_commands('testing', [keyword])

    with pytest.raises(SystemExit):
        cli.parser.parse_args(['testing', 'keyword', '-a', '1'])
Beispiel #7
0
def test_register_commands_verbose(monkeypatch, arguments, expected):
    """Test that register_commands handles quiet."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def verbosity(verbose):
        pass

    cli.register_commands('testing', [verbosity])

    args = cli.parser.parse_args(['testing', 'verbosity'] + arguments)
    assert args.verbose == expected
Beispiel #8
0
def test_register_commands_quiet_and_verbose_together_systemexit(monkeypatch):
    """Test that register_commands with quiet and verbose raises SystemExit."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def verbosity(quiet, verbose):
        pass

    cli.register_commands('testing', [verbosity])

    with pytest.raises(SystemExit):
        cli.parser.parse_args(['testing', 'verbosity', '-q', '-v'])
Beispiel #9
0
def test_register_commands_positional(monkeypatch):
    """Test register_commands with positional arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def positional(a, b):
        pass

    cli.register_commands('testing', [positional])

    args = cli.parser.parse_args(['testing', 'positional', '1', '2'])
    assert args.a == '1'
    assert args.b == '2'
Beispiel #10
0
def test_register_commands_keyword_only(monkeypatch, arguments, first, second):
    """Test register_commands with keyword-only arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(*, first=1, second=2):
        pass

    cli.register_commands('testing', [keyword])

    args = cli.parser.parse_args(['testing', 'keyword'] + arguments)
    assert args.first == first
    assert args.second == second
Beispiel #11
0
def test_register_commands_keyword(monkeypatch, arguments, a, b):
    """Test register_commands with keyword arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(a=1, b=2):
        pass

    cli.register_commands('testing', [keyword])

    args = cli.parser.parse_args(['testing', 'keyword'] + arguments)
    assert args.a == a
    assert args.b == b
Beispiel #12
0
def test_register_commands_positional(monkeypatch):
    """Test register_commands with positional arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def positional(a, b):
        pass

    cli.register_commands('testing', [positional])

    args = cli.parser.parse_args(['testing', 'positional', '1', '2'])
    assert args.a == '1'
    assert args.b == '2'
Beispiel #13
0
def test_register_commands_keyword_only(monkeypatch, arguments, first, second):
    """Test register_commands with keyword-only arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(*, first=1, second=2):
        pass

    cli.register_commands('testing', [keyword])

    args = cli.parser.parse_args(['testing', 'keyword'] + arguments)
    assert args.first == first
    assert args.second == second
Beispiel #14
0
def test_register_commands_keyword(monkeypatch, arguments, a, b):
    """Test register_commands with keyword arguments."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def keyword(a=1, b=2):
        pass

    cli.register_commands('testing', [keyword])

    args = cli.parser.parse_args(['testing', 'keyword'] + arguments)
    assert args.a == a
    assert args.b == b
Beispiel #15
0
def test_register_commands_quiet_and_verbose(monkeypatch, arguments, quiet,
                                             verbose):
    """Test that register_commands handles quiet and verbose."""
    monkeypatch.setattr(cli, 'parser', ArghParser('testing'))

    def verbosity(quiet, verbose):
        pass

    cli.register_commands('testing', [verbosity])

    args = cli.parser.parse_args(['testing', 'verbosity', arguments])
    assert args.quiet == quiet
    assert args.verbose == verbose