Commit efee5d9a authored by carlosperate's avatar carlosperate

Server: Update unit test following server refactoring

parent 734267f8
[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__.:
...@@ -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) err_out, exit_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
......
# -*- 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\nSketch Name could not be processed.' % e) print('Error: %s\nSketch Name could not be processed.' % e)
else: else:
if not os.path.exists(sketch_path): if not os.path.exists(sketch_path):
......
This diff is collapsed.
...@@ -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()
...@@ -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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment