Skip to content

Commit 1f6cd2c

Browse files
authored
feat: add travis ci (#12)
* feat: add travis ci * fix: downgrade pylint version Latest pylint availalbe for python2 is 1.9.4. * fix: exception in file_utils.py Python2 has no FileNotFoundError, so use IOError. * fix: install subprocess32 * fix: unit tests * chore: ignore some tests from Travis
1 parent 291f478 commit 1f6cd2c

File tree

8 files changed

+49
-22
lines changed

8 files changed

+49
-22
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
branches:
2+
only:
3+
- master
4+
language: python
5+
python:
6+
- "2.7"
7+
before_install:
8+
- pip install -U pip
9+
install:
10+
- python -m pip install --upgrade pip
11+
- pip install --upgrade -r requirements.txt
12+
script:
13+
- python -m flake8 --max-line-length=120 core core_tests data products tests
14+
- python -m nose core_tests/utils -v -s --nologcapture --with-doctest --with-xunit

core/utils/file_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"""
44
import errno
55
import os
6-
import shutil
76
import stat
87

8+
import shutil
9+
910
from core.log.log import Log
1011
from core.settings import Settings
1112

@@ -138,7 +139,7 @@ def clean(path):
138139
if os.path.isfile(path):
139140
File.write(path, text='')
140141
else:
141-
raise FileNotFoundError('Error: %s file not found' % path)
142+
raise IOError('Error: %s file not found' % path)
142143

143144
@staticmethod
144145
def find_by_extension(folder, extension):

core/utils/run.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import logging
22
import os
3-
import time
4-
from datetime import datetime
53

64
import psutil
5+
import time
6+
from datetime import datetime
77

88
from core.base_test.test_context import TestContext
99
from core.log.log import Log
1010
from core.settings import Settings
11-
from core.utils.file_utils import File
11+
from core.utils.file_utils import File, Folder
1212
from core.utils.process_info import ProcessInfo
1313

1414
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
3030

3131
# Command settings
3232
if not wait:
33+
# Ensure folder exists
34+
dir_path = os.path.dirname(os.path.realpath(log_file))
35+
Folder.create(dir_path)
36+
# Redirect output to file
3337
File.write(path=log_file, text=cmd + os.linesep + '====>' + os.linesep)
3438
cmd = cmd + ' >> ' + log_file + ' 2>&1 &'
3539

core_tests/utils/image_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_03_get_main_color(self):
3535
actual_color = ImageUtils.get_main_color(image_path=self.app_image)
3636
assert (actual_color == self.white).all(), 'Main color is wrong. It should be white.'
3737

38+
@unittest.skipIf(os.environ.get('TRAVIS', None) is not None, 'Skip on Travis.')
3839
def test_04_get_text(self):
3940
# OCR on Hello-World app
4041
text = ImageUtils.get_text(self.app_image)

core_tests/utils/process_tests.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import time
21
import unittest
32

3+
import time
4+
5+
from core.enums.os_type import OSType
6+
from core.settings import Settings
47
from core.utils.process import Process
58
from core.utils.run import run
69

710

811
class ProcessTests(unittest.TestCase):
12+
if Settings.HOST_OS == OSType.WINDOWS:
13+
http_module = 'http.server'
14+
else:
15+
http_module = 'SimpleHTTPServer'
916

1017
def test_30_kill_by_port(self):
1118
port = 4210
1219
self.start_server(port=port)
1320
time.sleep(0.5)
14-
running = Process.is_running_by_commandline(commandline='http.server')
21+
running = Process.is_running_by_commandline(commandline=self.http_module)
1522
assert running, 'Failed to start simple http server.'
1623
Process.kill_by_port(port=port)
1724
time.sleep(0.5)
18-
running = Process.is_running_by_commandline(commandline='http.server')
25+
running = Process.is_running_by_commandline(commandline=self.http_module)
1926
assert not running, 'Kill by port failed to kill process.'
2027

21-
@staticmethod
22-
def start_server(port):
23-
run(cmd='python -m http.server ' + str(port), wait=False)
28+
def start_server(self, port):
29+
run(cmd='python -m {0} {1}'.format(self.http_module, str(port)), wait=False)
2430

2531

2632
if __name__ == '__main__':

core_tests/utils/run_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os
2-
import time
32
import unittest
4-
from os.path import expanduser
53

4+
import time
65
from nose.tools import timed
76

87
from core.settings import Settings
@@ -13,29 +12,29 @@
1312

1413
# noinspection PyMethodMayBeStatic
1514
class RunTests(unittest.TestCase):
15+
current_file = os.path.basename(__file__)
16+
current_folder = os.path.dirname(os.path.realpath(__file__))
1617

1718
def tearDown(self):
1819
Process.kill_all_in_context()
1920

2021
def test_01_run_simple_command(self):
21-
home = expanduser("~")
22-
result = run(cmd='ls ' + home, wait=True, timeout=1)
22+
result = run(cmd='ls ' + self.current_folder, wait=True, timeout=1)
2323
assert result.exit_code == 0, 'Wrong exit code of successful command.'
2424
assert result.log_file is None, 'No log file should be generated if wait=True.'
2525
assert result.complete is True, 'Complete should be true when process execution is complete.'
2626
assert result.duration < 1, 'Process duration took too much time.'
27-
assert 'Desktop' in result.output, 'Listing home do not include Desktop folder.'
27+
assert self.current_file in result.output, 'Listing do not return correct output.'
2828

2929
def test_02_run_command_with_redirect(self):
30-
home = expanduser("~")
3130
out_file = os.path.join(Settings.TEST_OUT_HOME, 'log.txt')
32-
result = run(cmd='ls ' + home + ' > ' + out_file, wait=True, timeout=1)
31+
result = run(cmd='ls ' + self.current_folder + ' > ' + out_file, wait=True, timeout=1)
3332
assert result.exit_code == 0, 'Wrong exit code of successful command.'
3433
assert result.log_file is None, 'No log file should be generated if wait=True.'
3534
assert result.complete is True, 'Complete should be true when process execution is complete.'
3635
assert result.duration < 1, 'Process duration took too much time.'
3736
assert result.output == '', 'Output should be empty.'
38-
assert 'Desktop' in File.read(path=out_file)
37+
assert self.current_file in File.read(path=out_file)
3938

4039
def test_03_run_command_with_pipe(self):
4140
result = run(cmd='echo "test case" | wc -w ', wait=True, timeout=1)
@@ -77,6 +76,7 @@ def test_20_run_long_living_process(self):
7776
assert 'test' in File.read(result.log_file), 'Log file should contains output of the command.'
7877

7978
@timed(30)
79+
@unittest.skipIf(os.environ.get('TRAVIS', None) is not None, 'Skip on Travis.')
8080
def test_40_run_npm_pack(self):
8181
package = 'tns-core-modules'
8282
version = '5.0.0'

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ numpy>=1.15.4
1010
opencv-python>=3.4.3.18
1111
pytesseract>=0.2.5
1212
flake8>=3.6.0
13-
pylint>=2.2.2
13+
pylint>=1.9.4
1414
selenium>=3.141.0
15-
webdriver_manager>=1.7
15+
webdriver_manager>=1.7
16+
subprocess32>=3.5.3

requirements_darwin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ numpy>=1.15.4
1010
opencv-python>=3.4.3.18
1111
pytesseract>=0.2.5
1212
flake8>=3.6.0
13-
pylint>=2.2.2
13+
pylint>=1.9.4
1414
selenium>=3.141.0
1515
webdriver_manager>=1.7
1616
atomac>=1.1.0

0 commit comments

Comments
 (0)