Skip to content

Commit bc09278

Browse files
committed
updated tests and fixed some error wording
1 parent 8ab6c9b commit bc09278

15 files changed

+41
-36
lines changed

Diff for: commands/board/attach.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
4646
}
4747
sk, err := sketch.New(sketchPath)
4848
if err != nil {
49-
return nil, &commands.SketchNotFoundError{Cause: err}
49+
return nil, &commands.CantOpenSketchError{Cause: err}
5050
}
5151

5252
boardURI := req.GetBoardUri()

Diff for: commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
9999
sketchPath := paths.New(req.GetSketchPath())
100100
sk, err := sketch.New(sketchPath)
101101
if err != nil {
102-
return nil, &commands.SketchNotFoundError{Cause: err}
102+
return nil, &commands.CantOpenSketchError{Cause: err}
103103
}
104104

105105
fqbnIn := req.GetFqbn()

Diff for: commands/debug/debug_info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func getDebugProperties(req *debug.DebugConfigRequest, pm *packagemanager.Packag
4444
sketchPath := paths.New(req.GetSketchPath())
4545
sk, err := sketch.New(sketchPath)
4646
if err != nil {
47-
return nil, &commands.SketchNotFoundError{Cause: err}
47+
return nil, &commands.CantOpenSketchError{Cause: err}
4848
}
4949

5050
// XXX Remove this code duplication!!

Diff for: commands/errors.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,20 @@ func (e *MissingSketchPathError) ToRPCStatus() *status.Status {
304304
return status.New(codes.InvalidArgument, e.Error())
305305
}
306306

307-
// SketchNotFoundError is returned when the sketch is not found
308-
type SketchNotFoundError struct {
307+
// CantOpenSketchError is returned when the sketch is not found or cannot be opened
308+
type CantOpenSketchError struct {
309309
Cause error
310310
}
311311

312-
func (e *SketchNotFoundError) Error() string {
313-
return composeErrorMsg(tr("Sketch not found"), e.Cause)
312+
func (e *CantOpenSketchError) Error() string {
313+
return composeErrorMsg(tr("Can't open sketch"), e.Cause)
314314
}
315315

316-
func (e *SketchNotFoundError) Unwrap() error {
316+
func (e *CantOpenSketchError) Unwrap() error {
317317
return e.Cause
318318
}
319319

320-
func (e *SketchNotFoundError) ToRPCStatus() *status.Status {
320+
func (e *CantOpenSketchError) ToRPCStatus() *status.Status {
321321
return status.New(codes.NotFound, e.Error())
322322
}
323323

Diff for: commands/instances.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
862862
// TODO: This should be a ToRpc function for the Sketch struct
863863
sketch, err := sk.New(paths.New(req.SketchPath))
864864
if err != nil {
865-
return nil, &SketchNotFoundError{Cause: err}
865+
return nil, &CantOpenSketchError{Cause: err}
866866
}
867867

868868
otherSketchFiles := make([]string, sketch.OtherSketchFiles.Len())

Diff for: commands/sketch/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
4343

4444
s, err := sketch.New(sketchPath)
4545
if err != nil {
46-
return nil, &commands.SketchNotFoundError{Cause: err}
46+
return nil, &commands.CantOpenSketchError{Cause: err}
4747
}
4848

4949
sketchPath = s.FullPath

Diff for: commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
123123
sketchPath := paths.New(req.GetSketchPath())
124124
sk, err := sketch.New(sketchPath)
125125
if err != nil && req.GetImportDir() == "" && req.GetImportFile() == "" {
126-
return nil, &commands.SketchNotFoundError{Cause: err}
126+
return nil, &commands.CantOpenSketchError{Cause: err}
127127
}
128128

129129
pm := commands.GetPackageManager(req.GetInstance().GetId())

Diff for: test/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _run(cmd_string, custom_working_dir=None, custom_env=None):
141141
# It escapes spaces in the path using "\ " but it doesn't always work,
142142
# wrapping the path in quotation marks is the safest approach
143143
with run_context.prefix(f'{cd_command} "{custom_working_dir}"'):
144-
return run_context.run(cli_full_line, echo=False, hide=True, warn=True, env=custom_env, encoding="utf-8")
144+
return run_context.run(cli_full_line, echo=False, hide=False, warn=True, env=custom_env, encoding="utf-8")
145145

146146
return _run
147147

Diff for: test/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ markers =
1414
# -n=auto sets the numbers of parallel processes to use
1515
# --dist=loadfile distributes the tests in the parallel processes dividing them per file
1616
# See https://pypi.org/project/pytest-xdist/#parallelization for more info on parallelization
17-
addopts = -x -s --verbose --tb=long -n=auto --dist=loadfile
17+
addopts = -x -s --verbose

Diff for: test/test_board.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def test_board_details_no_flags(run_command):
528528
run_command("core install arduino:[email protected]")
529529
result = run_command("board details")
530530
assert not result.ok
531-
assert "Error getting board details: parsing fqbn: invalid fqbn:" in result.stderr
531+
assert "Error getting board details: Invalid FQBN:" in result.stderr
532532
assert result.stdout == ""
533533

534534

Diff for: test/test_compile.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
132132
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
133133
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
134134
# returning a different error detailed message
135-
assert "Error during build: opening sketch" in result.stderr
135+
assert "Error during build: Can't open sketch:" in result.stderr
136136
assert not result.ok
137137

138138
sketch_name = "CompileIntegrationTestSymlinkDirLoop"
@@ -154,7 +154,7 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
154154
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
155155
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
156156
# returning a different error detailed message
157-
assert "Error during build: opening sketch" in result.stderr
157+
assert "Error during build: Can't open sketch:" in result.stderr
158158
assert not result.ok
159159

160160

@@ -685,17 +685,17 @@ def test_compile_sketch_with_multiple_main_files(run_command, data_dir):
685685
# Build sketch from folder
686686
res = run_command(f"compile --clean -b {fqbn} {sketch_path}")
687687
assert res.failed
688-
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
688+
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr
689689

690690
# Build sketch from .ino file
691691
res = run_command(f"compile --clean -b {fqbn} {sketch_ino_file}")
692692
assert res.failed
693-
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
693+
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr
694694

695695
# Build sketch from .pde file
696696
res = run_command(f"compile --clean -b {fqbn} {sketch_pde_file}")
697697
assert res.failed
698-
assert "Error during build: opening sketch: multiple main sketch files found" in res.stderr
698+
assert "Error during build: Can't open sketch: multiple main sketch files found" in res.stderr
699699

700700

701701
def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
@@ -718,15 +718,15 @@ def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
718718
# * Compiling with sketch path
719719
res = run_command(f"compile --clean -b {fqbn} {sketch_path}")
720720
assert res.failed
721-
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
721+
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr
722722
# * Compiling with sketch main file
723723
res = run_command(f"compile --clean -b {fqbn} {sketch_main_file}")
724724
assert res.failed
725-
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
725+
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr
726726
# * Compiling in sketch path
727727
res = run_command(f"compile --clean -b {fqbn}", custom_working_dir=sketch_path)
728728
assert res.failed
729-
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
729+
assert "Error during build: Can't open sketch: no valid sketch found" in res.stderr
730730

731731

732732
def test_compile_with_only_compilation_database_flag(run_command, data_dir):

Diff for: test/test_core.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_core_updateindex_url_not_found(run_command, httpserver):
177177
result = run_command(f"core update-index --additional-urls={url}")
178178
assert result.failed
179179
lines = [l.strip() for l in result.stderr.splitlines()]
180-
assert f"Error updating index: downloading index {url}: 404 NOT FOUND" in lines
180+
assert f"Error updating index: Error downloading index '{url}': Server responded with: 404 NOT FOUND" in lines
181181

182182

183183
def test_core_updateindex_internal_server_error(run_command, httpserver):
@@ -190,7 +190,10 @@ def test_core_updateindex_internal_server_error(run_command, httpserver):
190190
result = run_command(f"core update-index --additional-urls={url}")
191191
assert result.failed
192192
lines = [l.strip() for l in result.stderr.splitlines()]
193-
assert f"Error updating index: downloading index {url}: 500 INTERNAL SERVER ERROR" in lines
193+
assert (
194+
f"Error updating index: Error downloading index '{url}': Server responded with: 500 INTERNAL SERVER ERROR"
195+
in lines
196+
)
194197

195198

196199
def test_core_install_without_updateindex(run_command):

Diff for: test/test_lib.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ def test_list_exit_code(run_command):
117117
# Verify lib list command fails because specified platform is not installed
118118
result = run_command("lib list -b arduino:samd:mkr1000")
119119
assert result.failed
120-
assert (
121-
result.stderr.strip() == "Error listing Libraries: loading board data: platform arduino:samd is not installed"
122-
)
120+
assert result.stderr.strip() == "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed"
123121

124122
assert run_command('lib install "AllThingsTalk LoRaWAN SDK"')
125123

126124
# Verifies lib list command keeps failing
127125
result = run_command("lib list -b arduino:samd:mkr1000")
128126
assert result.failed
129-
assert (
130-
result.stderr.strip() == "Error listing Libraries: loading board data: platform arduino:samd is not installed"
131-
)
127+
assert result.stderr.strip() == "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed"
132128

133129
assert run_command("core install arduino:samd")
134130

@@ -224,7 +220,7 @@ def test_install(run_command):
224220
# (https://github.com/arduino/arduino-cli/issues/534)
225221
res = run_command("lib install [email protected]")
226222
assert res.failed
227-
assert "Error resolving dependencies for [email protected]: dependency 'MD_MAX72xx' is not available" in res.stderr
223+
assert "No valid dependencies solution found: dependency 'MD_MAX72xx' is not available" in res.stderr
228224

229225

230226
def test_install_library_with_dependencies(run_command):

Diff for: test/test_sketch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ def test_sketch_archive_with_multiple_main_files(run_command, copy_sketch, worki
845845
assert res.failed
846846
assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr
847847
assert str(sketch_file.relative_to(sketch_dir)) in res.stderr
848-
assert "Error archiving: multiple main sketch files found" in res.stderr
848+
assert "Error archiving: Can't open sketch: multiple main sketch files found" in res.stderr
849849

850850

851851
def test_sketch_archive_case_mismatch_fails(run_command, data_dir):
@@ -859,4 +859,4 @@ def test_sketch_archive_case_mismatch_fails(run_command, data_dir):
859859

860860
res = run_command(f'sketch archive "{sketch_path}"')
861861
assert res.failed
862-
assert "Error archiving: no valid sketch found" in res.stderr
862+
assert "Error archiving: Can't open sketch: no valid sketch found" in res.stderr

Diff for: test/test_update.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def test_update_with_url_not_found(run_command, httpserver):
6363
res = run_command(f"update --additional-urls={url}")
6464
assert res.failed
6565
lines = [l.strip() for l in res.stderr.splitlines()]
66-
assert f"Error updating core and libraries index: downloading index {url}: 404 NOT FOUND" in lines
66+
assert (
67+
f"Error updating core and libraries index: Error downloading index '{url}':"
68+
" Server responded with: 404 NOT FOUND" in lines
69+
)
6770

6871

6972
def test_update_with_url_internal_server_error(run_command, httpserver):
@@ -76,7 +79,10 @@ def test_update_with_url_internal_server_error(run_command, httpserver):
7679
res = run_command(f"update --additional-urls={url}")
7780
assert res.failed
7881
lines = [l.strip() for l in res.stderr.splitlines()]
79-
assert f"Error updating core and libraries index: downloading index {url}: 500 INTERNAL SERVER ERROR" in lines
82+
assert (
83+
f"Error updating core and libraries index: Error downloading index '{url}':"
84+
" Server responded with: 500 INTERNAL SERVER ERROR" in lines
85+
)
8086

8187

8288
def test_update_showing_outdated_using_library_with_invalid_version(run_command, data_dir):

0 commit comments

Comments
 (0)