def test_load_arduino_cli_valid(self, mock_popen): """ Tests that a compiler path and arduino sketch path can be set and that a command line can be launched to open the sketch in the Arduino IDE. """ sketch_path = actions.create_sketch_default() ServerCompilerSettings().load_ide_option = 'open' with patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command expected_command = ['true', sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False) self.assertTrue(success) ServerCompilerSettings().load_ide_option = 'verify' with patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command mock_popen.return_value.communicate.return_value = ('test', 'test') mock_popen.return_value.returncode = 0 expected_command = ['true', '--verify', sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success) ServerCompilerSettings().load_ide_option = 'upload' with patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command mock_popen.return_value.communicate.return_value = ('test', 'test') mock_popen.return_value.returncode = 0 expected_command = [ 'true', '--upload', '--port', ServerCompilerSettings().get_serial_port_flag(), '--board', ServerCompilerSettings().get_arduino_board_flag(), sketch_path ] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success) # Test for unicode strings as Py2 can be susceptible to fail there ServerCompilerSettings().load_ide_option = 'upload' with patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'いろはにほへとちり' # unicode mock_popen.return_value.communicate.return_value = ( 'Γαζέες καὶ μυρτιὲς', 'Âne ex aéquo au whist') mock_popen.return_value.returncode = 0 expected_command = [ mock_compiler_dir.return_value, '--upload', '--port', ServerCompilerSettings().get_serial_port_flag(), '--board', ServerCompilerSettings().get_arduino_board_flag(), sketch_path ] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success)
def test_load_arduino_cli_valid(self, mock_popen): """ Tests that a compiler path and arduino sketch path can be set and that a command line can be launched to open the sketch in the Arduino IDE. """ sketch_path = actions.create_sketch_default() ServerCompilerSettings().load_ide_option = 'open' with mock.patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command expected_command = ['true', sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False) self.assertTrue(success) ServerCompilerSettings().load_ide_option = 'verify' with mock.patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command mock_popen.return_value.communicate.return_value = ('test', 'test') mock_popen.return_value.returncode = 0 expected_command = ['true', '--verify', sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success) ServerCompilerSettings().load_ide_option = 'upload' with mock.patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'true' # do nothing command mock_popen.return_value.communicate.return_value = ('test', 'test') mock_popen.return_value.returncode = 0 expected_command = [ 'true', '--upload', '--port', ServerCompilerSettings().get_serial_port_flag(), '--board', ServerCompilerSettings().get_arduino_board_flag(), sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success) # Test for unicode strings as Py2 can be susceptible to fail there ServerCompilerSettings().load_ide_option = 'upload' with mock.patch( 'ardublocklyserver.actions.ServerCompilerSettings.compiler_dir', new_callable=mock.PropertyMock) as mock_compiler_dir: mock_compiler_dir.return_value = 'いろはにほへとちり' # unicode mock_popen.return_value.communicate.return_value = ( 'Γαζέες καὶ μυρτιὲς', 'Âne ex aéquo au whist') mock_popen.return_value.returncode = 0 expected_command = [ mock_compiler_dir.return_value, '--upload', '--port', ServerCompilerSettings().get_serial_port_flag(), '--board', ServerCompilerSettings().get_arduino_board_flag(), sketch_path] success, conclusion, out, error, exit_code = \ actions.load_arduino_cli(sketch_path) mock_popen.assert_called_with(expected_command, shell=False, stderr=-1, stdout=-1) self.assertTrue(success)
def test_create_sketch_default(self): sketch_dir = actions.create_sketch_default() self.assertTrue(os.path.isfile(sketch_dir))