Skip to content

Commit e0e72f2

Browse files
authored
feat: migrate misc tests (#32)
* feat: migrate tests Migrated tests: - autocomplete - error reporting - setup - version Features in core: - Fix get class name - Enable creating test classes based on TnsTests without specifing setUp and tearDown methods
1 parent 5a13fe1 commit e0e72f2

File tree

7 files changed

+115
-19
lines changed

7 files changed

+115
-19
lines changed

core/base_test/tns_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=broad-except
12
import inspect
23
import os
34
import unittest
@@ -15,11 +16,15 @@
1516
from products.nativescript.tns import Tns
1617

1718

19+
# noinspection PyBroadException
1820
class TnsTest(unittest.TestCase):
1921
@classmethod
2022
def setUpClass(cls):
2123
# Get class name and log
22-
TestContext.CLASS_NAME = inspect.stack()[1][0].f_locals['cls'].__name__
24+
try:
25+
TestContext.CLASS_NAME = inspect.stack()[1][0].f_locals['cls'].__name__
26+
except Exception:
27+
TestContext.CLASS_NAME = cls.__name__
2328
Log.test_class_start(class_name=TestContext.CLASS_NAME)
2429

2530
# Kill processes
@@ -78,7 +83,7 @@ def tearDownClass(cls):
7883
Tns.kill()
7984
TnsTest.kill_emulators()
8085
Process.kill_all_in_context()
81-
Log.test_class_end(class_name=cls.__name__)
86+
Log.test_class_end(TestContext.CLASS_NAME)
8287

8388
@staticmethod
8489
def kill_emulators():

tests/cli/misc/autocomplete_tests.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Test for autocomplete command
3+
"""
4+
from core.base_test.tns_test import TnsTest
5+
from products.nativescript.tns import Tns
6+
7+
8+
# noinspection PyMethodMayBeStatic
9+
class AutocompleteTests(TnsTest):
10+
changed_to_enable = 'Restart your shell to enable command auto-completion.'
11+
changed_to_disable = 'Restart your shell to disable command auto-completion.'
12+
already_enabled = 'Autocompletion is already enabled.'
13+
enabled = 'Autocompletion is enabled.'
14+
disabled = 'Autocompletion is disabled.'
15+
16+
def test_001_autocomplete_enable_and_disable(self):
17+
# Force enable autocomplete.
18+
Tns.exec_command(command='autocomplete enable')
19+
20+
# Verify status
21+
result = Tns.exec_command(command='autocomplete status')
22+
assert self.enabled in result.output
23+
24+
# Disable autocomplete.
25+
result = Tns.exec_command(command='autocomplete disable')
26+
assert self.changed_to_disable in result.output
27+
28+
# Verify status
29+
result = Tns.exec_command(command='autocomplete status')
30+
assert self.disabled in result.output
31+
32+
# Enable again
33+
result = Tns.exec_command(command='autocomplete enable')
34+
assert self.changed_to_enable in result.output
35+
36+
# Enable once again
37+
result = Tns.exec_command(command='autocomplete enable')
38+
assert self.already_enabled in result.output
39+
40+
def test_400_autocomplete_invalid_parameter(self):
41+
result = Tns.exec_command(command='autocomplete fake')
42+
assert "This command doesn't accept parameters." in result.output
43+
assert 'This operation might modify the .bash_profile, .bashrc and .zshrc files.' in result.output
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Test for error-reporting command
3+
"""
4+
from core.base_test.tns_test import TnsTest
5+
from products.nativescript.tns import Tns
6+
7+
8+
# noinspection PyMethodMayBeStatic
9+
class ErrorReportingTests(TnsTest):
10+
11+
def test_001_error_reporting_enable(self):
12+
result = Tns.exec_command(command='error-reporting enable')
13+
assert 'Error reporting is now enabled.' in result.output
14+
result = Tns.exec_command(command='error-reporting status')
15+
assert 'Error reporting is enabled.' in result.output
16+
17+
def test_002_error_reporting_disable(self):
18+
result = Tns.exec_command(command='error-reporting disable')
19+
assert 'Error reporting is now disabled.' in result.output
20+
result = Tns.exec_command(command='error-reporting status')
21+
assert 'Error reporting is disabled.' in result.output
22+
23+
def test_401_error_reporting_with_invalid_parameter(self):
24+
result = Tns.exec_command(command='error-reporting fake')
25+
assert "The value 'fake' is not valid" in result.output
26+
assert "Valid values are 'enable', 'disable' and 'status'." in result.output

tests/cli/misc/misc.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#Tests to be writen
22

3-
**autocomplete**
4-
https://github.com/NativeScript/nativescript-cli/blob/master/docs/man_pages/general/autocomplete.md
5-
63
**setup**
74
https://github.com/NativeScript/nativescript-cli/blob/master/docs/man_pages/env-configuration/setup.md
85

tests/cli/misc/pacakge_manager_tests.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1+
"""
2+
Test for package-manager command
3+
"""
14
from core.base_test.tns_test import TnsTest
25
from products.nativescript.tns import Tns
36

47

58
# noinspection PyMethodMayBeStatic
69
class PackageManagerTests(TnsTest):
710

8-
@classmethod
9-
def setUpClass(cls):
10-
TnsTest.setUpClass()
11-
12-
def setUp(self):
13-
TnsTest.setUp(self)
14-
15-
def tearDown(self):
16-
TnsTest.tearDown(self)
17-
18-
@classmethod
19-
def tearDownClass(cls):
20-
TnsTest.tearDownClass()
21-
2211
def test_001_package_manager_get(self):
2312
result = Tns.exec_command(command='package-manager get')
2413
assert result.exit_code == 0, 'tns package-manager get exit with non zero exit code.'

tests/cli/misc/setup_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Test that check CLI package after installation.
3+
"""
4+
import os
5+
import unittest
6+
7+
from core.base_test.tns_test import TnsTest
8+
from core.enums.os_type import OSType
9+
from core.settings import Settings
10+
from core.utils.run import run
11+
12+
13+
class SetupTests(TnsTest):
14+
15+
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Skip on Linux and Windows')
16+
def test_300_mac_script_has_execution_permissions(self):
17+
script = os.path.join(Settings.TEST_RUN_HOME,
18+
'node_modules', 'nativescript', 'setup', 'mac-startup-shell-script.sh')
19+
result = run(cmd='ls -la {0}'.format(script))
20+
assert '-rwxr-xr-x' in result.output, 'macOS script has not execution permissions.'

tests/cli/misc/version_tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Test for `tns --version` command
3+
"""
4+
import re
5+
6+
from core.base_test.tns_test import TnsTest
7+
from products.nativescript.tns import Tns
8+
9+
10+
# noinspection PyMethodMayBeStatic
11+
class VersionTests(TnsTest):
12+
13+
def test_001_version(self):
14+
version = Tns.version()
15+
match = re.compile("^\\d+\\.\\d+\\.\\d+(-\\S+)?$").match(version)
16+
assert match, "{0} is not a valid version.".format(version)

0 commit comments

Comments
 (0)