Skip to content

[skip-changelog]Migrate tests from upload_test.py to test_upload.go #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Migrate TestUploadSketchWithPdeExtension from test_upload.py to uploa…
…d_test.go
  • Loading branch information
MatteoPologruto committed Dec 13, 2022
commit 74574c5a324932bbfebd7c2414a533ae9ae63547
61 changes: 61 additions & 0 deletions internal/integrationtest/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
)
Expand Down Expand Up @@ -340,3 +341,63 @@ func TestCompileAndUploadComboSketchWithPdeExtension(t *testing.T) {
require.Contains(t, string(stderr), sketchFile.String())
}
}

func TestUploadSketchWithPdeExtension(t *testing.T) {
if os.Getenv("CI") != "" {
t.Skip("VMs have no serial ports")
}

env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("update")
require.NoError(t, err)

sketchName := "UploadPdeSketch"
sketchPath := cli.SketchbookDir().Join(sketchName)

// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)

// Renames sketch file to pde
sketchFile := sketchPath.Join(sketchName + ".pde")
require.NoError(t, sketchPath.Join(sketchName+".ino").Rename(sketchFile))

for _, board := range detectedBoards(t, cli) {
// Install core
_, _, err = cli.Run("core", "install", board.core)
require.NoError(t, err)

// Compile sketch first
stdout, _, err := cli.Run("compile", "--clean", "-b", board.fqbn, sketchPath.String(), "--format", "json")
require.NoError(t, err)
buildDir := requirejson.Parse(t, stdout).Query(".builder_result | .build_path").String()
buildDir = strings.Trim(strings.ReplaceAll(buildDir, "\\\\", "\\"), "\"")

// Upload from sketch folder
waitForBoard(t, cli)
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, sketchPath.String())
require.NoError(t, err)

// Upload from sketch file
waitForBoard(t, cli)
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, sketchFile.String())
require.NoError(t, err)

waitForBoard(t, cli)
_, stderr, err := cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", buildDir)
require.NoError(t, err)
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")

// Upload from binary file
waitForBoard(t, cli)
// We don't need a specific file when using the --input-file flag to upload since
// it's just used to calculate the directory, so it's enough to get a random file
// that's inside that directory
binaryFile := paths.New(buildDir, sketchName+".pde.bin")
_, stderr, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-file", binaryFile.String())
require.NoError(t, err)
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")
}
}
49 changes: 0 additions & 49 deletions test/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,55 +42,6 @@ def test_upload_after_attach(run_command, data_dir, detected_boards):
assert run_command(["upload", sketch_path])


def test_upload_sketch_with_pde_extension(run_command, data_dir, detected_boards, wait_for_board):
assert run_command(["update"])

sketch_name = "UploadPdeSketch"
sketch_path = Path(data_dir, sketch_name)

# Create a test sketch
assert run_command(["sketch", "new", sketch_path])

# Renames sketch file to pde
sketch_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name}.pde")

for board in detected_boards:
# Install core
core = ":".join(board.fqbn.split(":")[:2])
assert run_command(["core", "install", core])

# Compile sketch first
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_path, "--format", "json"])
assert res.ok
data = json.loads(res.stdout)
build_dir = Path(data["builder_result"]["build_path"])

# Upload from sketch folder
wait_for_board()
assert run_command(["upload", "-b", board.fqbn, "-p", board.address, sketch_path])

# Upload from sketch file
wait_for_board()
assert run_command(["upload", "-b", board.fqbn, "-p", board.address, sketch_file])

wait_for_board()
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", build_dir])
assert (
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
)

# Upload from binary file
wait_for_board()
# We don't need a specific file when using the --input-file flag to upload since
# it's just used to calculate the directory, so it's enough to get a random file
# that's inside that directory
binary_file = next(build_dir.glob(f"{sketch_name}.pde.*"))
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-file", binary_file])
assert (
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
)


def test_upload_with_input_dir_containing_multiple_binaries(run_command, data_dir, detected_boards, wait_for_board):
# This tests verifies the behaviour outlined in this issue:
# https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
Expand Down