diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..adcf2701 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +branches: + only: + - master +language: python +python: + - "2.7" +before_install: + - pip install -U pip +install: + - python -m pip install --upgrade pip + - pip install --upgrade -r requirements.txt +script: + - python -m flake8 --max-line-length=120 core core_tests data products tests + - python -m nose core_tests/utils -v -s --nologcapture --with-doctest --with-xunit \ No newline at end of file diff --git a/core/utils/file_utils.py b/core/utils/file_utils.py index 19e9b8bd..afdf4d63 100644 --- a/core/utils/file_utils.py +++ b/core/utils/file_utils.py @@ -3,9 +3,10 @@ """ import errno import os -import shutil import stat +import shutil + from core.log.log import Log from core.settings import Settings @@ -138,7 +139,7 @@ def clean(path): if os.path.isfile(path): File.write(path, text='') else: - raise FileNotFoundError('Error: %s file not found' % path) + raise IOError('Error: %s file not found' % path) @staticmethod def find_by_extension(folder, extension): diff --git a/core/utils/run.py b/core/utils/run.py index 2b87924f..d6e21031 100644 --- a/core/utils/run.py +++ b/core/utils/run.py @@ -1,14 +1,14 @@ import logging import os -import time -from datetime import datetime import psutil +import time +from datetime import datetime from core.base_test.test_context import TestContext from core.log.log import Log from core.settings import Settings -from core.utils.file_utils import File +from core.utils.file_utils import File, Folder from core.utils.process_info import ProcessInfo if os.name == 'posix' and Settings.PYTHON_VERSION < 3: @@ -30,6 +30,10 @@ def run(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, timeout=600, fail_safe=False # Command settings if not wait: + # Ensure folder exists + dir_path = os.path.dirname(os.path.realpath(log_file)) + Folder.create(dir_path) + # Redirect output to file File.write(path=log_file, text=cmd + os.linesep + '====>' + os.linesep) cmd = cmd + ' >> ' + log_file + ' 2>&1 &' diff --git a/core_tests/utils/image_tests.py b/core_tests/utils/image_tests.py index c66efed8..0ce78d24 100644 --- a/core_tests/utils/image_tests.py +++ b/core_tests/utils/image_tests.py @@ -35,6 +35,7 @@ def test_03_get_main_color(self): actual_color = ImageUtils.get_main_color(image_path=self.app_image) assert (actual_color == self.white).all(), 'Main color is wrong. It should be white.' + @unittest.skipIf(os.environ.get('TRAVIS', None) is not None, 'Skip on Travis.') def test_04_get_text(self): # OCR on Hello-World app text = ImageUtils.get_text(self.app_image) diff --git a/core_tests/utils/process_tests.py b/core_tests/utils/process_tests.py index feea7c7f..643b6e3a 100644 --- a/core_tests/utils/process_tests.py +++ b/core_tests/utils/process_tests.py @@ -1,26 +1,32 @@ -import time import unittest +import time + +from core.enums.os_type import OSType +from core.settings import Settings from core.utils.process import Process from core.utils.run import run class ProcessTests(unittest.TestCase): + if Settings.HOST_OS == OSType.WINDOWS: + http_module = 'http.server' + else: + http_module = 'SimpleHTTPServer' def test_30_kill_by_port(self): port = 4210 self.start_server(port=port) time.sleep(0.5) - running = Process.is_running_by_commandline(commandline='http.server') + running = Process.is_running_by_commandline(commandline=self.http_module) assert running, 'Failed to start simple http server.' Process.kill_by_port(port=port) time.sleep(0.5) - running = Process.is_running_by_commandline(commandline='http.server') + running = Process.is_running_by_commandline(commandline=self.http_module) assert not running, 'Kill by port failed to kill process.' - @staticmethod - def start_server(port): - run(cmd='python -m http.server ' + str(port), wait=False) + def start_server(self, port): + run(cmd='python -m {0} {1}'.format(self.http_module, str(port)), wait=False) if __name__ == '__main__': diff --git a/core_tests/utils/run_tests.py b/core_tests/utils/run_tests.py index 7de3951d..251c71b0 100644 --- a/core_tests/utils/run_tests.py +++ b/core_tests/utils/run_tests.py @@ -1,8 +1,7 @@ import os -import time import unittest -from os.path import expanduser +import time from nose.tools import timed from core.settings import Settings @@ -13,29 +12,29 @@ # noinspection PyMethodMayBeStatic class RunTests(unittest.TestCase): + current_file = os.path.basename(__file__) + current_folder = os.path.dirname(os.path.realpath(__file__)) def tearDown(self): Process.kill_all_in_context() def test_01_run_simple_command(self): - home = expanduser("~") - result = run(cmd='ls ' + home, wait=True, timeout=1) + result = run(cmd='ls ' + self.current_folder, wait=True, timeout=1) assert result.exit_code == 0, 'Wrong exit code of successful command.' assert result.log_file is None, 'No log file should be generated if wait=True.' assert result.complete is True, 'Complete should be true when process execution is complete.' assert result.duration < 1, 'Process duration took too much time.' - assert 'Desktop' in result.output, 'Listing home do not include Desktop folder.' + assert self.current_file in result.output, 'Listing do not return correct output.' def test_02_run_command_with_redirect(self): - home = expanduser("~") out_file = os.path.join(Settings.TEST_OUT_HOME, 'log.txt') - result = run(cmd='ls ' + home + ' > ' + out_file, wait=True, timeout=1) + result = run(cmd='ls ' + self.current_folder + ' > ' + out_file, wait=True, timeout=1) assert result.exit_code == 0, 'Wrong exit code of successful command.' assert result.log_file is None, 'No log file should be generated if wait=True.' assert result.complete is True, 'Complete should be true when process execution is complete.' assert result.duration < 1, 'Process duration took too much time.' assert result.output == '', 'Output should be empty.' - assert 'Desktop' in File.read(path=out_file) + assert self.current_file in File.read(path=out_file) def test_03_run_command_with_pipe(self): result = run(cmd='echo "test case" | wc -w ', wait=True, timeout=1) @@ -77,6 +76,7 @@ def test_20_run_long_living_process(self): assert 'test' in File.read(result.log_file), 'Log file should contains output of the command.' @timed(30) + @unittest.skipIf(os.environ.get('TRAVIS', None) is not None, 'Skip on Travis.') def test_40_run_npm_pack(self): package = 'tns-core-modules' version = '5.0.0' diff --git a/requirements.txt b/requirements.txt index 4bdc3d57..11e447c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ numpy>=1.15.4 opencv-python>=3.4.3.18 pytesseract>=0.2.5 flake8>=3.6.0 -pylint>=2.2.2 +pylint>=1.9.4 selenium>=3.141.0 -webdriver_manager>=1.7 \ No newline at end of file +webdriver_manager>=1.7 +subprocess32>=3.5.3 \ No newline at end of file diff --git a/requirements_darwin.txt b/requirements_darwin.txt index 6719d948..29b7bd0b 100644 --- a/requirements_darwin.txt +++ b/requirements_darwin.txt @@ -10,7 +10,7 @@ numpy>=1.15.4 opencv-python>=3.4.3.18 pytesseract>=0.2.5 flake8>=3.6.0 -pylint>=2.2.2 +pylint>=1.9.4 selenium>=3.141.0 webdriver_manager>=1.7 atomac>=1.1.0