Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@
# name.
GIT_INIT_HAS_BRANCH = False

WINDOWS = platform.system() == 'Windows'

# We do NOT recommend or even advertise using backslashes on Windows because:
# - they are a quoting and escape nightmare, and
# - forward slashes work 99% of the time on Windows.
# But:
# - Backslashes should still work on Windows! So let's test them.
# - This helps catch OS-independent mistakes in both production code and test code
# where we hardcode forward slashes directly instead of using Python's Pathlib or os.path.
_scripts_west_cmds = r'scripts\\west-commands.yml' if WINDOWS else 'scripts///west-commands.yml'

# If you change this, keep the docstring in repos_tmpdir() updated also.
MANIFEST_TEMPLATE = '''\
MANIFEST_TEMPLATE = f'''\
manifest:
defaults:
remote: test-local
Expand All @@ -56,13 +67,11 @@
- name: net-tools
description: Networking tools.
clone-depth: 1
west-commands: scripts/west-commands.yml
west-commands: '{_scripts_west_cmds}'
self:
path: zephyr
'''

WINDOWS = platform.system() == 'Windows'

#
# Contextmanager
#
Expand Down Expand Up @@ -649,4 +658,5 @@ def check_proj_consistency(actual, expected):
)
assert actual.clone_depth == expected.clone_depth
assert actual.revision == expected.revision
assert actual.west_commands == expected.west_commands
for a, e in zip(actual.west_commands, expected.west_commands, strict=True):
assert PurePath(a) == PurePath(e)
10 changes: 6 additions & 4 deletions tests/test_extension_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import textwrap

from conftest import add_commit, cmd, cmd_raises
from conftest import WINDOWS, add_commit, cmd, cmd_raises


def test_extension_commands_basic(west_update_tmpdir):
Expand Down Expand Up @@ -218,11 +218,13 @@ def do_run(self, args, unknown):
def test_extension_command_multiple_commands_same_file(west_update_tmpdir):
# Test multiple commands defined in the same python file
net_tools_path = west_update_tmpdir / 'net-tools'
# Make sure we use either Pathlib or os.path
ext_file = r'scripts\\multi.py' if WINDOWS else 'scripts//multi.py'
add_commit(
net_tools_path,
'add multiple commands',
files={
'scripts/multi.py': textwrap.dedent('''\
ext_file: textwrap.dedent('''\
from west.commands import WestCommand

class FirstCommand(WestCommand):
Expand All @@ -241,9 +243,9 @@ def do_add_parser(self, parser_adder):
def do_run(self, args, unknown):
print('second command')
'''),
'scripts/west-commands.yml': textwrap.dedent('''\
'scripts/west-commands.yml': textwrap.dedent(f'''\
west-commands:
- file: scripts/multi.py
- file: {ext_file}
commands:
- name: first
class: FirstCommand
Expand Down
8 changes: 4 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def test_manifest_freeze(west_update_tmpdir):
'^ url: .*$',
'^ revision: [a-f0-9]{40}$',
'^ clone-depth: 1$',
'^ west-commands: scripts/west-commands.yml$',
r'^ west-commands: scripts[/\\]+west-commands.yml$',
'^ self:$',
'^ path: zephyr$',
]
Expand All @@ -459,7 +459,7 @@ def test_manifest_freeze_active(west_update_tmpdir):
'^ url: .*$',
'^ revision: [a-f0-9]{40}$',
'^ clone-depth: 1$',
'^ west-commands: scripts/west-commands.yml$',
r'^ west-commands: scripts[/\\]+west-commands.yml$',
'^ self:$',
'^ path: zephyr$',
]
Expand Down Expand Up @@ -491,7 +491,7 @@ def test_manifest_resolve(west_update_tmpdir):
'^ url: .*$',
'^ revision: master$',
'^ clone-depth: 1$',
'^ west-commands: scripts/west-commands.yml$',
r'^ west-commands: scripts[/\\]+west-commands.yml$',
'^ self:$',
'^ path: zephyr$',
]
Expand All @@ -515,7 +515,7 @@ def test_manifest_resolve_active(west_update_tmpdir):
'^ url: .*$',
'^ revision: master$',
'^ clone-depth: 1$',
'^ west-commands: scripts/west-commands.yml$',
r'^ west-commands: scripts[/\\]+west-commands.yml$',
'^ self:$',
'^ path: zephyr$',
]
Expand Down
Loading