west/tests/test_help.py

59 lines
1.6 KiB
Python
Raw Normal View History

# Copyright (c) 2020, Nordic Semiconductor ASA
import itertools
import os
import sys
tree-wide: move CLI into new west.app package This relates to issue #38, the TL;DR of which is that we've never gotten around to properly separating west's application internals from its API in source code, and instead relied on documentation to spell out exactly what the API was that users could rely on. Let's start fixing that by moving everything users can't rely on into a new west.app. This includes everything in west.commands except the __init__ module, so we can just make that a new src/west/commands.py file and have it be a module instead of a package. This lets its pykwalify schema file, west-commands-schema.yml, sit next to it in src/west, which is flatter than before. The code changes in this commit (source lines changed, rather than files just getting moved around) are: - change the entry point in setup.py to west.app.main:main - change some imports in src/west/app/main.py to import from west.app instead of west.commands - add a new src/west/app/__init__.py, since we're not using namespace packages - changes in MANIFEST.in and test_help.py to reflect new paths - adjust some comments and docstrings This change makes the API divide clearer. This in turn exposes some problems with our use of west.log from west.manifest: 1. logging to stdout is a bad practice from a library 2. west.log also uses global state (which relates to #149 also) which non-command-line users won't have set up properly (this is an example of why #1 is true) Subsequent commits will move to only using west.log from within west.app.* and the existing deprecated west.build and west.cmake APIs, which users should be migrating away from anyway. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-01-21 23:31:26 +08:00
from west.app.main import BUILTIN_COMMAND_GROUPS
from conftest import cmd
assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox"
def test_builtin_help_and_dash_h(west_init_tmpdir):
# Test "west help" and "west -h" are the same for built-in
# functionality.
h1out = cmd('help')
h2out = cmd('-h')
assert h1out == h2out
for cls in itertools.chain(*BUILTIN_COMMAND_GROUPS.values()):
c = cls()
h1out = cmd(f'help {c.name}')
h2out = cmd(f'{c.name} -h')
assert h1out == h2out
def test_extension_help_and_dash_h(west_init_tmpdir):
# Test "west help <command>" and "west <command> -h" for extension
# commands (west_init_tmpdir has a command with one).
cmd('update')
ext1out = cmd('help test-extension')
ext2out = cmd('test-extension -h')
expected = EXTENSION_EXPECTED
if sys.platform == 'win32':
# Manage gratuitous incompatibilities:
#
# - multiline python strings are \n separated even on windows
# - the windows command help output gets an extra newline
expected = [os.linesep.join(case.splitlines()) + os.linesep
for case in EXTENSION_EXPECTED]
assert ext1out == ext2out
assert ext1out in expected
# argparse changed its behavior at some point; patch over that here.
EXTENSION_EXPECTED = ['''\
usage: west test-extension [-h]
optional arguments:
-h, --help show this help message and exit
''', '''\
usage: west test-extension [-h]
options:
-h, --help show this help message and exit
''']