From bd8ddf75064904c98b1c022559656e4cb4fffd7b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 21 Apr 2016 17:26:34 +0100 Subject: [PATCH] fix tests --- openlp/core/common/__init__.py | 2 +- openlp/plugins/media/mediaplugin.py | 6 +++--- openlp/plugins/presentations/lib/pdfcontroller.py | 4 ++-- .../openlp_plugins/media/test_mediaplugin.py | 14 +++++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 2c32a75d0..2384252fc 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -378,7 +378,7 @@ def clean_filename(filename): return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) -def check_binary(program_path): +def check_binary_exists(program_path): """ Function that checks whether a binary exists. diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 5f3f4f3ef..1d5529084 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -30,7 +30,7 @@ from shutil import which from PyQt5 import QtCore -from openlp.core.common import AppLocation, Settings, translate, check_binary, is_win +from openlp.core.common import AppLocation, Settings, translate, check_binary_exists, is_win from openlp.core.lib import Plugin, StringContent, build_icon from openlp.plugins.media.lib import MediaMediaItem, MediaTab @@ -159,8 +159,8 @@ def process_check_binary(program_path): :return: If exists or not """ program_type = None - runlog = check_binary(program_path) - print(runlog) + runlog = check_binary_exists(program_path) + print(runlog, type(runlog)) # Analyse the output to see it the program is mediainfo for line in runlog.splitlines(): decoded_line = line.decode() diff --git a/openlp/plugins/presentations/lib/pdfcontroller.py b/openlp/plugins/presentations/lib/pdfcontroller.py index 0ef9cb29b..48150a9f2 100644 --- a/openlp/plugins/presentations/lib/pdfcontroller.py +++ b/openlp/plugins/presentations/lib/pdfcontroller.py @@ -26,7 +26,7 @@ import re from shutil import which from subprocess import check_output, CalledProcessError -from openlp.core.common import AppLocation, check_binary +from openlp.core.common import AppLocation, check_binary_exists from openlp.core.common import Settings, is_win from openlp.core.lib import ScreenList from .presentationcontroller import PresentationController, PresentationDocument @@ -69,7 +69,7 @@ class PdfController(PresentationController): :return: Type of the binary, 'gs' if ghostscript, 'mudraw' if mudraw, None if invalid. """ program_type = None - runlog = check_binary(program_path) + runlog = check_binary_exists(program_path) # Analyse the output to see it the program is mudraw, ghostscript or neither for line in runlog.splitlines(): decoded_line = line.decode() diff --git a/tests/functional/openlp_plugins/media/test_mediaplugin.py b/tests/functional/openlp_plugins/media/test_mediaplugin.py index e7852fb0c..c49cdbaa4 100644 --- a/tests/functional/openlp_plugins/media/test_mediaplugin.py +++ b/tests/functional/openlp_plugins/media/test_mediaplugin.py @@ -64,24 +64,28 @@ class MediaPluginTest(TestCase, TestMixin): # THEN: about() should return a non-empty string self.assertNotEquals(len(MediaPlugin.about()), 0) - def process_check_binary_pass_test(self): + @patch('openlp.plugins.media.mediaplugin.check_binary_exists') + def process_check_binary_pass_test(self, mocked_checked_binary_exists): """ Test that the Process check returns true if found """ # GIVEN: A media plugin instance # WHEN: function is called with the correct name - result = process_check_binary("MediaInfo") + mocked_checked_binary_exists.return_value = str.encode('MediaInfo Command line') + result = process_check_binary('MediaInfo') # THEN: The the result should be True - self.assertFalse(result, "Media info should have been found") + self.assertTrue(result, 'Mediainfo should have been found') - def process_check_binary_fail_test(self): + @patch('openlp.plugins.media.mediaplugin.check_binary_exists') + def process_check_binary_fail_test(self, mocked_checked_binary_exists): """ Test that the Process check returns false if not found """ # GIVEN: A media plugin instance # WHEN: function is called with the wrong name + mocked_checked_binary_exists.return_value = str.encode('MediaInfo1 Command line') result = process_check_binary("MediaInfo1") # THEN: The the result should be True - self.assertTrue(result, "Media info should not have been found") + self.assertFalse(result, "Mediainfo should not have been found")