Skip to content

Commit

Permalink
test: replace str(path) to os.path.join
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Dec 15, 2023
1 parent d85951f commit 5e584dd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 45 deletions.
25 changes: 11 additions & 14 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from copy import (
deepcopy,
)
from pathlib import (
Path,
)

import pytest
from conftest import (
Expand All @@ -32,9 +29,9 @@
@pytest.mark.skipif(not shutil.which('idf.py'), reason='idf.py not found')
class TestBuild:
def test_build_hello_world(self, tmpdir, capsys):
path = Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world'
path = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')

app = CMakeApp(str(path), 'esp32', work_dir=str(tmpdir / 'test'))
app = CMakeApp(path, 'esp32', work_dir=str(tmpdir / 'test'))
app.build()

captured = capsys.readouterr()
Expand All @@ -58,9 +55,9 @@ def test_build_hello_world(self, tmpdir, capsys):
def test_build_with_modified_components(
self, tmpdir, capsys, modified_components, check_app_dependencies, build_status
):
path = Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world'
path = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')

app = CMakeApp(str(path), 'esp32', work_dir=str(tmpdir / 'test'))
app = CMakeApp(path, 'esp32', work_dir=str(tmpdir / 'test'))
app.build(
modified_components=modified_components,
check_app_dependencies=check_app_dependencies,
Expand All @@ -71,19 +68,19 @@ def test_build_with_modified_components(
'modified_files, build_status',
[
('/foo', BuildStatus.SKIPPED),
(str(Path(IDF_PATH) / 'examples' / 'README.md'), BuildStatus.SKIPPED),
([str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md')], BuildStatus.SKIPPED),
(os.path.join(IDF_PATH, 'examples', 'README.md'), BuildStatus.SKIPPED),
([os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md')], BuildStatus.SKIPPED),
(
[
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md'),
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'main' / 'hello_world_main.c'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'main', 'hello_world_main.c'),
],
BuildStatus.SUCCESS,
),
],
)
def test_build_with_modified_files(self, modified_files, build_status):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')

app = CMakeApp(test_dir, 'esp32')
app.build(
Expand All @@ -95,7 +92,7 @@ def test_build_with_modified_files(self, modified_files, build_status):
assert app.build_status == build_status

def test_build_without_modified_components_but_ignored_app_dependency_check(self):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')

apps = find_apps(
test_dir,
Expand All @@ -110,7 +107,7 @@ def test_build_without_modified_components_but_ignored_app_dependency_check(self
assert app.build_status == BuildStatus.SUCCESS

def test_build_with_junit_output(self, tmpdir):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')

apps = [
CMakeApp(test_dir, 'esp32', build_dir='build_1'),
Expand Down
66 changes: 35 additions & 31 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def test_manifest_rootpath_specified(self):
'esp32',
recursive=True,
manifest_files=str(yaml_file),
manifest_rootpath=str(Path(IDF_PATH) / 'examples'),
manifest_rootpath=os.path.join(IDF_PATH, 'examples'),
)

def test_keyword_idf_target(self, tmpdir):
test_dir = str(Path(IDF_PATH) / 'examples')
test_dir = os.path.join(IDF_PATH, 'examples')
apps = find_apps(test_dir, 'esp32', recursive=True)
assert apps

Expand Down Expand Up @@ -153,19 +153,19 @@ def test_with_depends_and_modified_components(self, tmpdir, modified_components,
'modified_files, could_find_apps',
[
('/foo', False),
(str(Path(IDF_PATH) / 'examples' / 'README.md'), False),
([str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md')], False),
(os.path.join(IDF_PATH, 'examples', 'README.md'), False),
([os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md')], False),
(
[
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md'),
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'main' / 'hello_world_main.c'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'main', 'hello_world_main.c'),
],
True,
),
],
)
def test_with_depends_components_but_modified(self, tmp_path, modified_files, could_find_apps):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')
apps = find_apps(test_dir, 'esp32', recursive=True)
assert apps

Expand All @@ -183,7 +183,7 @@ def test_with_depends_components_but_modified(self, tmp_path, modified_files, co
test_dir,
'esp32',
recursive=True,
manifest_files=yaml_file,
manifest_files=str(yaml_file),
modified_components=[],
modified_files=modified_files,
)
Expand All @@ -195,13 +195,13 @@ def test_with_depends_components_but_modified(self, tmp_path, modified_files, co
@pytest.mark.parametrize(
'modified_components, modified_files, could_find_apps',
[
([], str(Path(IDF_PATH) / 'examples' / 'README.md'), (True, False)),
(None, [str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md')], (True, True)),
([], os.path.join(IDF_PATH, 'examples', 'README.md'), (True, False)),
(None, [os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md')], (True, True)),
(
[],
[
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md'),
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'main' / 'hello_world_main.c'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'main', 'hello_world_main.c'),
],
(True, True),
),
Expand All @@ -210,7 +210,7 @@ def test_with_depends_components_but_modified(self, tmp_path, modified_files, co
def test_with_depends_components_and_filepatterns(
self, tmp_path, modified_components, modified_files, could_find_apps
):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')
apps = find_apps(test_dir, 'esp32', recursive=True)
assert apps

Expand All @@ -229,7 +229,7 @@ def test_with_depends_components_and_filepatterns(
test_dir,
'esp32',
recursive=True,
manifest_files=yaml_file,
manifest_files=str(yaml_file),
modified_components=modified_components,
)
if could_find_apps[0]:
Expand All @@ -253,8 +253,8 @@ def test_with_depends_components_and_filepatterns(
test_dir,
'esp32',
recursive=True,
manifest_rootpath=str(IDF_PATH),
manifest_files=yaml_file,
manifest_rootpath=IDF_PATH,
manifest_files=str(yaml_file),
modified_components=modified_components,
modified_files=modified_files,
)
Expand All @@ -267,20 +267,20 @@ def test_with_depends_components_and_filepatterns(
'modified_files, could_find_apps',
[
(None, True),
(str(Path(IDF_PATH) / 'examples' / 'README.md'), True),
([str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md')], True),
(os.path.join(IDF_PATH, 'examples', 'README.md'), True),
([os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md')], True),
(
[
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'README.md'),
str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world' / 'main' / 'hello_world_main.c'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'README.md'),
os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world', 'main', 'hello_world_main.c'),
],
True,
),
([str(Path(IDF_PATH) / 'examples' / 'a.c')], True),
([os.path.join(IDF_PATH, 'examples', 'a.c')], True),
],
)
def test_with_filepattern_but_calculate_component_later(self, modified_files, could_find_apps):
test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')
apps = find_apps(test_dir, 'esp32', recursive=True)
assert apps

Expand Down Expand Up @@ -310,7 +310,7 @@ def test_with_skipped_but_included(self, tmp_path):

class TestFindWithSdkconfigFiles:
def test_with_sdkconfig_defaults_idf_target(self):
test_dir = str(Path(IDF_PATH) / 'examples')
test_dir = os.path.join(IDF_PATH, 'examples')
apps = find_apps(test_dir, 'esp32', recursive=True)
assert apps

Expand Down Expand Up @@ -352,13 +352,13 @@ def test_with_sdkconfig_defaults_idf_target_but_disabled(self, tmp_path):
sdkconfig_defaults = tmp_path / 'sdkconfig.defaults'
sdkconfig_defaults.write_text('CONFIG_IDF_TARGET="esp32s2"')

test_dir = str(Path(IDF_PATH) / 'examples' / 'get-started' / 'hello_world')
test_dir = os.path.join(IDF_PATH, 'examples', 'get-started', 'hello_world')
assert not find_apps(
test_dir,
'esp32s2',
recursive=True,
sdkconfig_defaults=str(sdkconfig_defaults),
manifest_files=[manifest_file],
manifest_files=[str(manifest_file)],
)

def test_with_config_rules(self, tmp_path, monkeypatch):
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_config_name_in_manifest(self, tmp_path):
'esp32',
recursive=True,
config_rules_str=['sdkconfig.ci.*=', 'sdkconfig.ci=default'],
manifest_files=yaml_file,
manifest_files=str(yaml_file),
)
assert len(apps) == 1
assert apps[0].sdkconfig_files == [
Expand All @@ -508,7 +508,7 @@ def test_config_name_in_manifest(self, tmp_path):
'esp32s2',
recursive=True,
config_rules_str=['sdkconfig.ci.*=', 'sdkconfig.ci=default'],
manifest_files=yaml_file,
manifest_files=str(yaml_file),
)
assert len(apps) == 1
assert apps[0].sdkconfig_files == [
Expand All @@ -520,15 +520,19 @@ def test_config_name_in_manifest(self, tmp_path):
'esp32s3',
recursive=True,
config_rules_str=['sdkconfig.ci.*=', 'sdkconfig.ci=default'],
manifest_files=yaml_file,
manifest_files=str(yaml_file),
)
assert len(apps) == 1
assert apps[0].sdkconfig_files == [
str(tmp_path / 'test1' / 'sdkconfig.defaults'),
str(tmp_path / 'test1' / 'sdkconfig.ci'),
]
apps = find_apps(
str(tmp_path / 'test1'), 'esp32s3', recursive=True, config_rules_str=['=default'], manifest_files=yaml_file
str(tmp_path / 'test1'),
'esp32s3',
recursive=True,
config_rules_str=['=default'],
manifest_files=str(yaml_file),
)
assert len(apps) == 1
assert apps[0].sdkconfig_files == [
Expand Down Expand Up @@ -565,7 +569,7 @@ def test_env_var(self, tmp_path, monkeypatch):
str(tmp_path / 'test1'),
'esp32',
config_rules_str=['sdkconfig.ci=default', 'sdkconfig.ci.*='],
manifest_files=yaml_file,
manifest_files=str(yaml_file),
)
assert len(apps) == 2
assert apps[0].sdkconfig_files == [
Expand All @@ -582,7 +586,7 @@ def test_env_var(self, tmp_path, monkeypatch):
str(tmp_path / 'test1'),
'esp32',
config_rules_str=['sdkconfig.ci=default', 'sdkconfig.ci.*='],
manifest_files=yaml_file,
manifest_files=str(yaml_file),
)
assert len(apps) == 3
monkeypatch.delenv('TEST_ENV_VAR')
Expand Down

0 comments on commit 5e584dd

Please sign in to comment.