Skip to content

feat: add travis ci #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 18, 2019
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions core/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions core/utils/run.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 &'

Expand Down
1 change: 1 addition & 0 deletions core_tests/utils/image_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions core_tests/utils/process_tests.py
Original file line number Diff line number Diff line change
@@ -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__':
Expand Down
16 changes: 8 additions & 8 deletions core_tests/utils/run_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
webdriver_manager>=1.7
subprocess32>=3.5.3
2 changes: 1 addition & 1 deletion requirements_darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down