Skip to content

Commit

Permalink
Fix bug in device.sync that prevented it from working on some drives (#…
Browse files Browse the repository at this point in the history
…141)

* Fix bug in device.sync that prevented it from working on some drives

device.sync wasn't working when the source folder was on a different drive than the temp directory.

I think the intention of the code was to get the path without the drive specifier by getting the relative path of it when compared to the drive specifier. However the temp file driver specifier was being passed through rather than the source file one.

* Fix preprocess_src_file on windows when paths are on different drives.

* fix test

---------

Co-authored-by: Brian Pugh <[email protected]>
  • Loading branch information
TimAidley and BrianPugh authored Jun 11, 2023
1 parent 239bbf1 commit 7e5b824
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion belay/device_sync_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def preprocess_src_file(
tmp_dir = Path(tmp_dir)
src_file = Path(src_file)

transformed = tmp_dir / src_file.relative_to(tmp_dir.anchor) if src_file.is_absolute() else tmp_dir / src_file
transformed = tmp_dir / src_file.relative_to(src_file.anchor) if src_file.is_absolute() else tmp_dir / src_file
transformed.parent.mkdir(parents=True, exist_ok=True)

if src_file.suffix == ".py":
Expand Down
20 changes: 19 additions & 1 deletion tests/test_device_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def test_preprocess_src_file_default_py(tmp_path):
assert actual == Path("foo/bar/baz.py")


def test_preprocess_src_file_cross_mpy(tmp_path, mocker):
def test_preprocess_src_file_cross_mpy_relative(tmp_path, mocker):
mock_check_output = mocker.patch("belay.device_sync_support.subprocess.check_output")
actual = device_sync_support.preprocess_src_file(
tmp_path,
Expand All @@ -434,6 +434,24 @@ def test_preprocess_src_file_cross_mpy(tmp_path, mocker):
assert actual.as_posix().endswith("foo/bar/baz.mpy")


@pytest.mark.skipif(os.name != "nt", reason="Runs only on Windows")
def test_preprocess_src_file_cross_mpy_absolute(mocker):
mock_check_output = mocker.patch("belay.device_sync_support.subprocess.check_output")
actual = device_sync_support.preprocess_src_file(
"C:/tmp/abc123",
"D:/foo/bar/baz.py",
False,
"fake-mpy-cross-binary",
)
mock_check_output.assert_called_once()
call = mock_check_output.call_args_list[0][0][0]
assert call[0] == "fake-mpy-cross-binary"
assert call[1] == "-o"
assert call[2].as_posix() == "C:/tmp/abc123/foo/bar/baz.mpy"
assert call[3].as_posix() == "D:/foo/bar/baz.py"
assert actual.as_posix() == "C:/tmp/abc123/foo/bar/baz.mpy"


def test_preprocess_src_file_default_generic(tmp_path):
actual = device_sync_support.preprocess_src_file(tmp_path, "foo/bar/baz.generic", False, None)
assert actual == Path("foo/bar/baz.generic")
Expand Down

0 comments on commit 7e5b824

Please sign in to comment.