Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
efee5d9a
Commit
efee5d9a
authored
May 05, 2017
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Server: Update unit test following server refactoring
parent
734267f8
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
760 additions
and
238 deletions
+760
-238
.coveragerc
.coveragerc
+16
-0
ardublocklyserver/actions.py
ardublocklyserver/actions.py
+13
-11
ardublocklyserver/sketchcreator.py
ardublocklyserver/sketchcreator.py
+7
-8
ardublocklyserver/tests/actions_test.py
ardublocklyserver/tests/actions_test.py
+693
-208
ardublocklyserver/tests/run_all.py
ardublocklyserver/tests/run_all.py
+2
-2
ardublocklyserver/tests/sketchcreator_test.py
ardublocklyserver/tests/sketchcreator_test.py
+29
-9
No files found.
.coveragerc
0 → 100644
View file @
efee5d9a
[run]
branch = False
cover_pylib = False
source = ardublocklyserver/
omit =
ardublocklyserver/tests/*
ardublocklyserver/local-packages/*
ardublocklyserver/pyserialports/*
[report]
show_missing = True
skip_covered = False
exclude_lines =
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ardublocklyserver/actions.py
View file @
efee5d9a
...
@@ -53,8 +53,8 @@ def load_arduino_cli(sketch_path):
...
@@ -53,8 +53,8 @@ def load_arduino_cli(sketch_path):
parameter.
parameter.
:param sketch_path: Path to the sketch to load into the Arduino IDE.
:param sketch_path: Path to the sketch to load into the Arduino IDE.
:return: A tuple with the following data (success,
conclusion, out, error
,
:return: A tuple with the following data (success,
ide_mode, std_out
,
exit_code)
e
rr_out, e
xit_code)
"""
"""
success
=
True
success
=
True
ide_mode
=
'unknown'
ide_mode
=
'unknown'
...
@@ -79,15 +79,17 @@ def load_arduino_cli(sketch_path):
...
@@ -79,15 +79,17 @@ def load_arduino_cli(sketch_path):
success
=
False
success
=
False
exit_code
=
54
exit_code
=
54
err_out
=
'Launch IDE option not configured in the Settings.'
err_out
=
'Launch IDE option not configured in the Settings.'
elif
settings
.
load_ide_option
==
'upload'
:
elif
not
settings
.
get_arduino_board_flag
()
and
(
if
not
settings
.
get_serial_port_flag
():
settings
.
load_ide_option
==
'upload'
or
success
=
False
settings
.
load_ide_option
==
'verify'
):
exit_code
=
55
success
=
False
err_out
=
'Serial Port configured in Settings not accessible.'
exit_code
=
56
if
not
settings
.
get_arduino_board_flag
():
err_out
=
'Arduino Board not configured in the Settings.'
success
=
False
elif
not
settings
.
get_serial_port_flag
()
and
\
exit_code
=
56
settings
.
load_ide_option
==
'upload'
:
err_out
=
'Arduino Board not configured in the Settings.'
success
=
False
exit_code
=
55
err_out
=
'Serial Port configured in Settings not accessible.'
if
success
:
if
success
:
ide_mode
=
settings
.
load_ide_option
ide_mode
=
settings
.
load_ide_option
...
...
ardublocklyserver/sketchcreator.py
View file @
efee5d9a
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
"""Sketch Creator module creates an Arduino Sketch source code file.
# Sketch Creator module creates an Arduino Sketch source code file.
#
Copyright (c) 2017 carlosperate https://github.com/carlosperate/
# Copyright (c) 2017 carlosperate https://github.com/carlosperate/
Licensed under the Apache License, Version 2.0 (the "License"):
# Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
"""
#
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
import
codecs
import
codecs
import
os
import
os
...
@@ -72,7 +71,7 @@ def build_sketch_path(sketch_dir, sketch_name):
...
@@ -72,7 +71,7 @@ def build_sketch_path(sketch_dir, sketch_name):
if
os
.
path
.
isdir
(
sketch_dir
):
if
os
.
path
.
isdir
(
sketch_dir
):
try
:
try
:
sketch_path
=
os
.
path
.
join
(
sketch_dir
,
sketch_name
)
sketch_path
=
os
.
path
.
join
(
sketch_dir
,
sketch_name
)
except
TypeError
as
e
:
except
(
TypeError
,
AttributeError
)
as
e
:
print
(
'Error: %s
\n
Sketch Name could not be processed.'
%
e
)
print
(
'Error: %s
\n
Sketch Name could not be processed.'
%
e
)
else
:
else
:
if
not
os
.
path
.
exists
(
sketch_path
):
if
not
os
.
path
.
exists
(
sketch_path
):
...
...
ardublocklyserver/tests/actions_test.py
View file @
efee5d9a
This diff is collapsed.
Click to expand it.
ardublocklyserver/tests/run_all.py
View file @
efee5d9a
...
@@ -27,8 +27,8 @@ from compilersettings_test import ServerCompilerSettingsTestCase
...
@@ -27,8 +27,8 @@ from compilersettings_test import ServerCompilerSettingsTestCase
from
actions_test
import
ActionsTestCase
from
actions_test
import
ActionsTestCase
def
run_
all_
tests
():
def
run_tests
():
unittest
.
main
()
unittest
.
main
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
run_
all_
tests
()
run_tests
()
ardublocklyserver/tests/sketchcreator_test.py
View file @
efee5d9a
...
@@ -15,14 +15,12 @@ import unittest
...
@@ -15,14 +15,12 @@ import unittest
try
:
try
:
from
ardublocklyserver
import
sketchcreator
from
ardublocklyserver
import
sketchcreator
from
ardublocklyserver.compilersettings
import
ServerCompilerSettings
except
ImportError
:
except
ImportError
:
import
sys
import
sys
file_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
file_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
package_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
file_dir
))
package_dir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
file_dir
))
sys
.
path
.
insert
(
0
,
package_dir
)
sys
.
path
.
insert
(
0
,
package_dir
)
from
ardublocklyserver
import
sketchcreator
from
ardublocklyserver
import
sketchcreator
from
ardublocklyserver.compilersettings
import
ServerCompilerSettings
class
SketchCreatorTestCase
(
unittest
.
TestCase
):
class
SketchCreatorTestCase
(
unittest
.
TestCase
):
...
@@ -32,6 +30,8 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -32,6 +30,8 @@ class SketchCreatorTestCase(unittest.TestCase):
the test directory where it can create and delete files.
the test directory where it can create and delete files.
"""
"""
temp_folder
=
None
#
#
# Test fixtures
# Test fixtures
#
#
...
@@ -68,14 +68,14 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -68,14 +68,14 @@ class SketchCreatorTestCase(unittest.TestCase):
#
#
# Tests for file creation
# Tests for file creation
#
#
def
test_sketch_name_default
(
self
):
def
test_
create_
sketch_name_default
(
self
):
"""Test default sketch has created the file correctly."""
"""Test default sketch has created the file correctly."""
sketch_path
=
sketchcreator
.
create_sketch
(
self
.
temp_folder
)
sketch_path
=
sketchcreator
.
create_sketch
(
self
.
temp_folder
)
self
.
assertEqual
(
sketch_path
,
self
.
default_sketch_path
)
self
.
assertEqual
(
sketch_path
,
self
.
default_sketch_path
)
self
.
assertTrue
(
os
.
path
.
isfile
(
self
.
default_sketch_path
))
self
.
assertTrue
(
os
.
path
.
isfile
(
self
.
default_sketch_path
))
def
test_sketch_name_non_default
(
self
):
def
test_
create_
sketch_name_non_default
(
self
):
"""Tests to see if an Arduino Sketch is created in a new location."""
"""Tests to see if an Arduino Sketch is created in a new location."""
filename_unicode
=
'TestTemp_ろΓαζςÂé'
filename_unicode
=
'TestTemp_ろΓαζςÂé'
final_ino_path
=
os
.
path
.
join
(
final_ino_path
=
os
.
path
.
join
(
...
@@ -87,7 +87,7 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -87,7 +87,7 @@ class SketchCreatorTestCase(unittest.TestCase):
self
.
assertEqual
(
final_ino_path
,
created_sketch_path
)
self
.
assertEqual
(
final_ino_path
,
created_sketch_path
)
self
.
assertTrue
(
os
.
path
.
isfile
(
final_ino_path
))
self
.
assertTrue
(
os
.
path
.
isfile
(
final_ino_path
))
def
test_sketch_name_invalid
(
self
):
def
test_
create_
sketch_name_invalid
(
self
):
"""Test for invalid inputs in the create_sketch method."""
"""Test for invalid inputs in the create_sketch method."""
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
invalid_sketch_name
=
True
invalid_sketch_name
=
True
...
@@ -98,7 +98,7 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -98,7 +98,7 @@ class SketchCreatorTestCase(unittest.TestCase):
self
.
assertIsNone
(
created_sketch_path
)
self
.
assertIsNone
(
created_sketch_path
)
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
def
test_sketch_path_invalid
(
self
):
def
test_
create_
sketch_path_invalid
(
self
):
"""Test for invalid inputs in the create_sketch method."""
"""Test for invalid inputs in the create_sketch method."""
invalid_path
=
os
.
path
.
join
(
self
.
temp_folder
,
'raNd_dIr'
)
invalid_path
=
os
.
path
.
join
(
self
.
temp_folder
,
'raNd_dIr'
)
self
.
assertFalse
(
os
.
path
.
isdir
(
invalid_path
))
self
.
assertFalse
(
os
.
path
.
isdir
(
invalid_path
))
...
@@ -111,7 +111,7 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -111,7 +111,7 @@ class SketchCreatorTestCase(unittest.TestCase):
#
#
# Tests for code content
# Tests for code content
#
#
def
test_sketch_code_default
(
self
):
def
test_
create_
sketch_code_default
(
self
):
"""Test default sketch has filled the sketch contents correctly."""
"""Test default sketch has filled the sketch contents correctly."""
sketch_path
=
sketchcreator
.
create_sketch
(
self
.
temp_folder
)
sketch_path
=
sketchcreator
.
create_sketch
(
self
.
temp_folder
)
...
@@ -119,7 +119,7 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -119,7 +119,7 @@ class SketchCreatorTestCase(unittest.TestCase):
sketch_content
=
sketch
.
read
()
sketch_content
=
sketch
.
read
()
self
.
assertEqual
(
sketch_content
,
sketchcreator
.
default_sketch_code
)
self
.
assertEqual
(
sketch_content
,
sketchcreator
.
default_sketch_code
)
def
test_sketch_code_non_default
(
self
):
def
test_
create_
sketch_code_non_default
(
self
):
"""Test sketch is created correctly with the given code."""
"""Test sketch is created correctly with the given code."""
sketch_code
=
'Unicode test (ろΓαζςÂaé) on: %s'
%
\
sketch_code
=
'Unicode test (ろΓαζςÂaé) on: %s'
%
\
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
)
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
)
...
@@ -131,7 +131,7 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -131,7 +131,7 @@ class SketchCreatorTestCase(unittest.TestCase):
sketch_code_read
=
sketch
.
read
()
sketch_code_read
=
sketch
.
read
()
self
.
assertEqual
(
sketch_code_read
,
sketch_code
)
self
.
assertEqual
(
sketch_code_read
,
sketch_code
)
def
test_sketch_code_invalid
(
self
):
def
test_
create_
sketch_code_invalid
(
self
):
"""Test for invalid inputs in the create_sketch method."""
"""Test for invalid inputs in the create_sketch method."""
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
invalid_sketch_code
=
True
invalid_sketch_code
=
True
...
@@ -142,6 +142,26 @@ class SketchCreatorTestCase(unittest.TestCase):
...
@@ -142,6 +142,26 @@ class SketchCreatorTestCase(unittest.TestCase):
self
.
assertIsNone
(
created_sketch_path
)
self
.
assertIsNone
(
created_sketch_path
)
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
self
.
assertFalse
(
os
.
path
.
isdir
(
self
.
default_sketch_path
))
#
# Test for building sketch path
#
def
test_build_sketch_path_sketch_name_invalid
(
self
):
"""Test for invalid sketch_name Type."""
returned_sketch_path
=
sketchcreator
.
build_sketch_path
(
sketch_dir
=
self
.
temp_folder
,
sketch_name
=
True
)
self
.
assertIsNone
(
returned_sketch_path
)
def
test_build_sketch_path_do_not_make_dir
(
self
):
"""Test when the sketch directory exists already."""
os
.
makedirs
(
os
.
path
.
join
(
self
.
temp_folder
,
'sketch_name'
))
returned_sketch_path
=
sketchcreator
.
build_sketch_path
(
sketch_dir
=
self
.
temp_folder
,
sketch_name
=
'sketch_name'
)
self
.
assertEqual
(
returned_sketch_path
,
os
.
path
.
join
(
self
.
temp_folder
,
'sketch_name'
,
'sketch_name.ino'
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment