Skip to content

Commit

Permalink
tests: Add alias testing
Browse files Browse the repository at this point in the history
Add simple test cases to verify alias' functionality.

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed Jul 18, 2024
1 parent 256b3aa commit 6aec00d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2024, Basalte bv

import os

import pytest

from conftest import cmd

assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox"

@pytest.fixture(autouse=True)
def autouse_tmpdir(config_tmpdir, west_init_tmpdir):
# Since this module tests west's configuration file features,
# adding autouse=True to the config_tmpdir and west_init_tmpdir fixtures
# saves typing and is less error-prone than using it below in every test case.
pass

def test_alias_commands():
cmd('config alias.test1 topdir')
cmd('config --global alias.test2 topdir')
cmd('config --system alias.test3 topdir')

topdir_out = cmd('topdir')

assert cmd('test1') == topdir_out
assert cmd('test2') == topdir_out
assert cmd('test3') == topdir_out

def test_alias_recursive_commands():
cmd('config alias.test1 topdir')
cmd('config alias.test2 test1')

assert cmd('test2') == cmd('topdir')

def test_alias_command_with_arguments():
list_format = '"{revision}"'
cmd(f'config alias.revs "list -f {list_format}"')

assert cmd('revs') == cmd(f'list -f {list_format}')

def test_alias_override():
before = cmd('list')
list_format = '"{name}:{revision}"'
formatted = cmd(f'list -f {list_format}')

cmd(f'config alias.list "list -f {list_format}"')

after = cmd('list')

assert before != after
assert formatted == after

0 comments on commit 6aec00d

Please sign in to comment.