Skip to content

Commit ae28d9a

Browse files
committed
refactor: BaseTest is now TnsTest
Do not use BaseTest, in future we may have multiple base tests. For example base test for CLI tests, base tests for schematics tests and so on.
1 parent 6aee241 commit ae28d9a

21 files changed

+338
-184
lines changed

core/base_test/base_test.py renamed to core/base_test/tns_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from products.nativescript.tns import Tns
1515

1616

17-
class BaseTest(unittest.TestCase):
17+
class TnsTest(unittest.TestCase):
1818
@classmethod
1919
def setUpClass(cls):
2020
# Get class name and log
@@ -24,7 +24,7 @@ def setUpClass(cls):
2424
# Kill processes
2525
Tns.kill()
2626
Gradle.kill()
27-
BaseTest.kill_emulators()
27+
TnsTest.kill_emulators()
2828

2929
# Ensure log folders are create
3030
Folder.create(Settings.TEST_OUT_HOME)
@@ -65,7 +65,7 @@ def tearDownClass(cls):
6565
Logic executed after all core_tests in class.
6666
"""
6767
Tns.kill()
68-
BaseTest.kill_emulators()
68+
TnsTest.kill_emulators()
6969
for process in TestContext.STARTED_PROCESSES:
7070
Log.info("Kill Process: " + os.linesep + process.commandline)
7171
Process.kill_pid(process.pid)

core_tests/core/device_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import os
22

3-
from core.base_test.base_test import BaseTest
3+
from core.base_test.tns_test import TnsTest
44
from core.enums.device_type import DeviceType
55
from core.settings import Settings
66
from core.utils.device.device_manager import DeviceManager
77
from core.utils.device.emulator_info import EmulatorInfo
88

99

1010
# noinspection PyMethodMayBeStatic
11-
class DeviceTests(BaseTest):
11+
class DeviceTests(TnsTest):
1212

1313
@classmethod
1414
def setUpClass(cls):
15-
BaseTest.setUpClass()
15+
TnsTest.setUpClass()
1616

1717
def setUp(self):
18-
BaseTest.setUp(self)
18+
TnsTest.setUp(self)
1919

2020
def tearDown(self):
2121
DeviceManager.Emulator.stop()
2222
DeviceManager.Simulator.stop()
23-
BaseTest.tearDown(self)
23+
TnsTest.tearDown(self)
2424

2525
@classmethod
2626
def tearDownClass(cls):
27-
BaseTest.tearDownClass()
27+
TnsTest.tearDownClass()
2828

2929
def test_01_emulator(self):
3030
# Verify emulator is started properly

core_tests/products/tns_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from nose.tools import timed
44

5-
from core.base_test.base_test import BaseTest
5+
from core.base_test.tns_test import TnsTest
66
from core.enums.os_type import OSType
77
from core.settings import Settings
88
from core.utils.device.device_manager import DeviceManager
@@ -11,30 +11,30 @@
1111
from products.nativescript.tns import Tns
1212

1313

14-
class TnsTests(BaseTest):
14+
class TnsTests(TnsTest):
1515
app_name = Settings.AppName.DEFAULT
1616
app_folder = os.path.join(Settings.TEST_RUN_HOME, app_name)
1717
emu = None
1818
sim = None
1919

2020
@classmethod
2121
def setUpClass(cls):
22-
BaseTest.setUpClass()
22+
TnsTest.setUpClass()
2323
Tns.create(app_name=cls.app_name)
2424
cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT)
2525
if Settings.HOST_OS is OSType.OSX:
2626
cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
2727

2828
def setUp(self):
29-
BaseTest.setUp(self)
29+
TnsTest.setUp(self)
3030

3131
def tearDown(self):
3232
Tns.kill()
33-
BaseTest.tearDown(self)
33+
TnsTest.tearDown(self)
3434

3535
@classmethod
3636
def tearDownClass(cls):
37-
BaseTest.tearDownClass()
37+
TnsTest.tearDownClass()
3838

3939
@timed(300)
4040
def test_001_tns_run_android(self):

products/nativescript/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ def is_dependency(app_name, dependency):
3232
return True
3333
return False
3434

35+
@staticmethod
36+
def install_dependency(app_name, dependency, version='latest'):
37+
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
38+
Npm.uninstall(package=dependency, option='--save', folder=app_path)
39+
Npm.install(package='{0}@{1}'.format(dependency, version), option='--save', folder=app_path)
40+
41+
@staticmethod
42+
def install_dev_dependency(app_name, dependency, version='latest'):
43+
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
44+
Npm.uninstall(package=dependency, option='--save-dev', folder=app_path)
45+
Npm.install(package='{0}@{1}'.format(dependency, version), option='--save-dev', folder=app_path)
46+
3547
@staticmethod
3648
def update(app_name, modules=True, angular=True, typescript=True, web_pack=True, ns_plugins=False):
3749
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)

products/nativescript/tns.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Tns(object):
1616
@staticmethod
1717
def exec_command(command, cwd=Settings.TEST_RUN_HOME, platform=Platform.NONE, path=None, device=None, release=False,
1818
for_device=False, provision=Settings.IOS.DEV_PROVISION, bundle=False, aot=False, uglify=False,
19-
snapshot=False, log_trace=False, justlaunch=False, wait=True):
19+
snapshot=False, log_trace=False, justlaunch=False, wait=True, timeout=600):
2020
"""
2121
Execute tns command.
2222
:param command: Tns command.
@@ -34,6 +34,7 @@ def exec_command(command, cwd=Settings.TEST_RUN_HOME, platform=Platform.NONE, pa
3434
:param log_trace: If true pass `--log trace` to command.
3535
:param justlaunch: If true pass `--justlaunch` to command.
3636
:param wait: If true it will wait until command is complete.
37+
:param timeout: Timeout for CLI command (respected only if wait=True).
3738
:return: ProcessInfo object.
3839
:rtype: core.utils.process_info.ProcessInfo
3940
"""
@@ -68,7 +69,7 @@ def exec_command(command, cwd=Settings.TEST_RUN_HOME, platform=Platform.NONE, pa
6869
cmd += ' --justlaunch'
6970
if log_trace:
7071
cmd += ' --log trace'
71-
return Run.command(cmd=cmd, cwd=cwd, wait=wait, log_level=logging.INFO)
72+
return Run.command(cmd=cmd, cwd=cwd, wait=wait, log_level=logging.INFO, timeout=timeout)
7273

7374
@staticmethod
7475
def create(app_name=Settings.AppName.DEFAULT, template=None, path=None, app_id=None,
@@ -127,10 +128,19 @@ def create(app_name=Settings.AppName.DEFAULT, template=None, path=None, app_id=N
127128

128129
return result
129130

131+
@staticmethod
132+
def platform_remove(app_name=Settings.AppName.DEFAULT, platform=Platform.NONE, verify=True,
133+
log_trace=False):
134+
command = 'platform remove ' + str(platform) + ' --path ' + app_name
135+
result = Tns.exec_command(command=command, log_trace=log_trace)
136+
if verify:
137+
# TODO: Implement it!
138+
pass
139+
return result
140+
130141
@staticmethod
131142
def platform_add(app_name=Settings.AppName.DEFAULT, platform=Platform.NONE, framework_path=None, version=None,
132-
verify=True,
133-
log_trace=False):
143+
verify=True, log_trace=False):
134144
platform_add_string = str(platform)
135145
if version is not None:
136146
platform_add_string = platform_add_string + '@' + version
@@ -257,13 +267,25 @@ def debug(app_name, platform, device=None, release=False, provision=Settings.IOS
257267
def doctor(app_name=None):
258268
"""
259269
Execute `tns doctor`
260-
:param app_name: App where command will be executed (by default None -> doctor will be executed outside app).
270+
:param app_name: App where command will be executed (by default None -> common will be executed outside app).
261271
:return: Result of `tns doctor` command.
262272
"""
263273
cwd = Settings.TEST_RUN_HOME
264274
if app_name is not None:
265275
cwd = os.path.join(cwd, app_name)
266-
return Tns.exec_command(command='doctor', cwd=cwd)
276+
return Tns.exec_command(command='doctor', cwd=cwd, timeout=60)
277+
278+
@staticmethod
279+
def info(app_name=None):
280+
"""
281+
Execute `tns info`
282+
:param app_name: App where command will be executed (by default None -> common will be executed outside app).
283+
:return: Result of `tns info` command.
284+
"""
285+
cwd = Settings.TEST_RUN_HOME
286+
if app_name is not None:
287+
cwd = os.path.join(cwd, app_name)
288+
return Tns.exec_command(command='info', cwd=cwd, timeout=60)
267289

268290
@staticmethod
269291
def version():

run_common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __get_templates():
4747
raise IOError("Failed to clone and pack template: " + app.repo)
4848

4949

50-
# noinspection SpellCheckingInspection
5150
def __get_packages():
5251
"""
5352
Get NativeScript CLI and runtimes in TEST_SUT_HOME.

run_ns.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
if __name__ == '__main__':
99
run_common.prepare()
1010
Log.info("Running core_tests...")
11-
# noinspection SpellCheckingInspection
1211
arguments = ['nosetests', '-v', '-s', '--nologcapture', '--with-doctest', '--with-xunit', '--with-flaky']
1312
for i in sys.argv:
1413
arguments.append(str(i))

run_schematics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
if __name__ == '__main__':
99
run_common.prepare(shared=True)
1010
Log.info("Running core_tests...")
11-
# noinspection SpellCheckingInspection
1211
arguments = ['nosetests', '-v', '-s', '--nologcapture', '--with-doctest', '--with-xunit', '--with-flaky']
1312
for i in sys.argv:
1413
arguments.append(str(i))

tests/__init__.py

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import os
2+
3+
from core.base_test.tns_test import TnsTest
4+
from core.enums.os_type import OSType
5+
from core.enums.platform_type import Platform
6+
from core.settings import Settings
7+
from data.templates import Template
8+
from products.nativescript.app import App
9+
from products.nativescript.tns import Tns
10+
11+
RETRY_COUNT = 3
12+
APP_NAME = Settings.AppName.DEFAULT
13+
14+
15+
# noinspection PyMethodMayBeStatic
16+
class DoctorFunctionalTests(TnsTest):
17+
ANDROID_HOME = os.environ.get('ANDROID_HOME')
18+
JAVA_HOME = os.environ.get('JAVA_HOME')
19+
20+
@classmethod
21+
def setUpClass(cls):
22+
TnsTest.setUpClass()
23+
24+
def setUp(self):
25+
TnsTest.setUp(self)
26+
os.environ['ANDROID_HOME'] = self.ANDROID_HOME
27+
os.environ['JAVA_HOME'] = self.JAVA_HOME
28+
29+
@classmethod
30+
def tearDownClass(cls):
31+
TnsTest.tearDownClass()
32+
33+
def test_001_doctor(self):
34+
result = Tns.doctor()
35+
assert result.exit_code == 0, 'Doctor exit with non zero exit code.'
36+
37+
output = result.output
38+
assert 'No issues were detected.' in output
39+
assert 'Your ANDROID_HOME environment variable is set and points to correct directory.' in output
40+
assert 'Your adb from the Android SDK is correctly installed.' in output
41+
assert 'The Android SDK is installed.' in output
42+
assert 'A compatible Android SDK for compilation is found.' in output
43+
assert 'Javac is installed and is configured properly.' in output
44+
assert 'The Java Development Kit (JDK) is installed and is configured properly.' in output
45+
if Settings.HOST_OS != OSType.OSX:
46+
assert 'Local builds for iOS can be executed only on a macOS system. To build for iOS on a different ' \
47+
'operating system, you can use the NativeScript cloud infrastructure.' in output
48+
else:
49+
assert 'Xcode is installed and is configured properly.' in output
50+
assert 'xcodeproj is installed and is configured properly.' in output
51+
assert 'CocoaPods are installed.' in output
52+
assert 'CocoaPods update is not required.' in output
53+
assert 'CocoaPods are configured properly.' in output
54+
assert 'Your current CocoaPods version is newer than 1.0.0' in output
55+
assert 'Python installed and configured correctly.' in output
56+
assert "The Python 'six' package is found." in output
57+
58+
def test_200_doctor_show_warning_when_new_components_are_available(self):
59+
Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_JS.local_package, update=False)
60+
Tns.platform_add_android(app_name=APP_NAME, version='4')
61+
App.install_dependency(app_name=APP_NAME, dependency='tns-core-modules', version='4')
62+
63+
doctor_result = Tns.doctor(app_name=APP_NAME)
64+
doctor_output = doctor_result.output
65+
66+
info_result = Tns.info(app_name=APP_NAME)
67+
info_output = info_result.output
68+
69+
for output in (doctor_output, info_output):
70+
assert 'Update available for component tns-core-modules' in output
71+
assert 'Update available for component tns-android' in output
72+
73+
def test_400_doctor_should_detect_wrong_path_to_android_sdk(self):
74+
os.environ['ANDROID_HOME'] = 'WRONG_PATH'
75+
output = Tns.doctor().output
76+
assert 'There seem to be issues with your configuration.' in output
77+
assert 'The ANDROID_HOME environment variable is not set or it points to a non-existent directory' in output
78+
79+
def test_401_doctor_should_detect_wrong_path_to_java(self):
80+
os.environ['JAVA_HOME'] = 'WRONG_PATH'
81+
output = Tns.doctor().output
82+
assert "Error executing command 'javac'." in output
83+
assert 'The Java Development Kit (JDK) is not installed or is not configured properly.' in output

tests/cli/run/webpack/hello_word_js_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import unittest
33

4-
from core.base_test.base_test import BaseTest
4+
from core.base_test.tns_test import TnsTest
55
from core.enums.os_type import OSType
66
from core.enums.platform_type import Platform
77
from core.settings import Settings
@@ -15,7 +15,7 @@
1515
from products.nativescript.tns import Tns
1616

1717

18-
class TnsRunJSTests(BaseTest):
18+
class TnsRunJSTests(TnsTest):
1919
app_name = Settings.AppName.DEFAULT
2020
source_project_dir = os.path.join(Settings.TEST_RUN_HOME, app_name)
2121
target_project_dir = os.path.join(Settings.TEST_RUN_HOME, 'data', 'temp', app_name)
@@ -24,7 +24,7 @@ class TnsRunJSTests(BaseTest):
2424

2525
@classmethod
2626
def setUpClass(cls):
27-
BaseTest.setUpClass()
27+
TnsTest.setUpClass()
2828

2929
# Boot emulator and simulator
3030
cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT)
@@ -42,7 +42,7 @@ def setUpClass(cls):
4242
Folder.copy(source=cls.source_project_dir, target=cls.target_project_dir)
4343

4444
def setUp(self):
45-
BaseTest.setUp(self)
45+
TnsTest.setUp(self)
4646
# "src" folder of TestApp will be restored before each test.
4747
# This will ensure failures in one test do not cause common failures.
4848
source_src = os.path.join(self.target_project_dir, 'app')
@@ -52,7 +52,7 @@ def setUp(self):
5252

5353
@classmethod
5454
def tearDownClass(cls):
55-
BaseTest.tearDownClass()
55+
TnsTest.tearDownClass()
5656

5757

5858
class RunAndroidJSTests(TnsRunJSTests):

0 commit comments

Comments
 (0)