Skip to content

Commit 904fe5a

Browse files
authored
fix: sync tests (#4)
* refactor: sync tests * refactor: use IntEnum instead of Enum
1 parent 84a9f4a commit 904fe5a

17 files changed

+378
-253
lines changed

core/enums/app_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Application type enum.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class AppType(Enum):
7+
class AppType(IntEnum):
88
_init_ = 'value string'
99

1010
JS = 1, 'js'

core/enums/device_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Device type enum.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class DeviceType(Enum):
7+
class DeviceType(IntEnum):
88
_init_ = 'value string'
99

1010
EMU = 1, 'emulator'

core/enums/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Environment type.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class EnvironmentType(Enum):
7+
class EnvironmentType(IntEnum):
88
_init_ = 'value string'
99

1010
NEXT = 1, 'next'

core/enums/os_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Host OS enum.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class OSType(Enum):
7+
class OSType(IntEnum):
88
_init_ = 'value string'
99

1010
WINDOWS = 1, 'Windows'

core/enums/platform_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
{N} Platform Type.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class Platform(Enum):
7+
class Platform(IntEnum):
88
_init_ = 'value string'
99

1010
ANDROID = 1, 'android'

core/enums/styling_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
22
Styling type enum.
33
"""
4-
from aenum import Enum
4+
from aenum import IntEnum
55

66

7-
class StylingType(Enum):
7+
class StylingType(IntEnum):
88
_init_ = 'value string'
99

1010
CSS = 1, 'css'

core_tests/utils/app.android.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Import app variables@import 'app-variables';// Import the theme’s main ruleset - both index and platform specific.@import '~nativescript-theme-core/scss/index';@import '~nativescript-theme-core/scss/platforms/index.android';// Import common styles@import 'app-common';// Place any CSS rules you want to apply only on Android here.action-item { padding-right: 10;}

core_tests/utils/file_tests.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import unittest
3+
4+
from settings import Settings
5+
from utils.file_utils import File
6+
7+
8+
# noinspection PyMethodMayBeStatic
9+
class FileUtilsTests(unittest.TestCase):
10+
11+
def test_01_replace(self):
12+
# Path to files
13+
base_path = os.path.join(Settings.TEST_RUN_HOME, 'core_tests', 'utils')
14+
old_scss = os.path.join(base_path, 'app.android.scss')
15+
new_scss = os.path.join(base_path, 'app.android.add_style.scss')
16+
old_value = 'Android here'
17+
new_value = 'Android here\n.page { background-color: red;}'
18+
19+
# Create new file (so we don't break original one).
20+
File.copy(src=old_scss, target=new_scss)
21+
assert len(File.read(path=new_scss).split('\n')) == 14, 'Unexpected lines count.'
22+
23+
# Replace
24+
File.replace(path=new_scss, old_string=old_value, new_string=new_value)
25+
content = File.read(path=new_scss)
26+
assert 'red;' in content, 'Failed to replace string.'
27+
assert len(content.split('\n')) == 15, 'Unexpected lines count.'
28+
29+
# Revert
30+
File.replace(path=new_scss, old_string=new_value, new_string=old_value)
31+
content = File.read(path=new_scss)
32+
assert 'red;' not in content, 'Failed to replace string.'
33+
assert len(content.split('\n')) == 14, 'Unexpected lines count.'
34+
35+
File.clean(path=new_scss)
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()

core_tests/utils/process_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ def test_30_kill_by_port(self):
1111
port = 4210
1212
self.start_server(port=port)
1313
time.sleep(0.5)
14-
running = Process.is_running_by_commandline(commandline='SimpleHTTPServer')
14+
running = Process.is_running_by_commandline(commandline='http.server')
1515
assert running, 'Failed to start simple http server.'
1616
Process.kill_by_port(port=port)
1717
time.sleep(0.5)
18-
running = Process.is_running_by_commandline(commandline='SimpleHTTPServer')
18+
running = Process.is_running_by_commandline(commandline='http.server')
1919
assert not running, 'Kill by port failed to kill process.'
2020

2121
@staticmethod
2222
def start_server(port):
23-
run(cmd='python -m SimpleHTTPServer ' + str(port), wait=False)
23+
run(cmd='python -m http.server ' + str(port), wait=False)
2424

2525

2626
if __name__ == '__main__':

data/changes.py

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import os
22

3+
from const import Colors
34
from core.settings import Settings
45
from core.utils.file_utils import File
56

67

78
# noinspection PyShadowingBuiltins
89
class ChangeSet(object):
9-
def __init__(self, file, old_value, new_value):
10+
def __init__(self, file, old_value, new_value, old_text=None, new_text=None, old_color=None, new_color=None):
1011
self.file = file
1112
self.old_value = old_value
1213
self.new_value = new_value
14+
self.old_text = old_text
15+
self.new_text = new_text
16+
self.old_color = old_color
17+
self.new_color = new_color
1318

1419

1520
class Sync(object):
@@ -26,34 +31,84 @@ def revert(app_name, change_set):
2631

2732
class Changes(object):
2833
class JSHelloWord(object):
29-
JS = ChangeSet(file=os.path.join('app', 'main-view-model.js'), old_value='taps left', new_value='clicks left')
30-
CSS = ChangeSet(file=os.path.join('app', 'app.css'), old_value='font-size: 18', new_value='font-size: 50')
31-
XML = ChangeSet(file=os.path.join('app', 'main-page.xml'), old_value='TAP', new_value='HIT')
34+
JS = ChangeSet(file=os.path.join('app', 'main-view-model.js'),
35+
old_value='taps left', new_value='clicks left',
36+
old_text='taps left', new_text='clicks left')
37+
CSS = ChangeSet(file=os.path.join('app', 'app.css'),
38+
old_value='font-size: 18', new_value='font-size: 50',
39+
old_color=None, new_color=None)
40+
XML = ChangeSet(file=os.path.join('app', 'main-page.xml'),
41+
old_value='TAP', new_value='HIT',
42+
old_text='TAP', new_text='HIT')
3243

3344
class TSHelloWord(object):
34-
TS = ChangeSet(file=os.path.join('app', 'main-view-model.ts'), old_value='taps left', new_value='clicks left')
35-
CSS = ChangeSet(file=os.path.join('app', 'app.css'), old_value='font-size: 18', new_value='font-size: 50')
36-
XML = ChangeSet(file=os.path.join('app', 'main-page.xml'), old_value='TAP', new_value='HIT')
45+
TS = ChangeSet(file=os.path.join('app', 'main-view-model.ts'),
46+
old_value='taps left', new_value='clicks left',
47+
old_text='taps left', new_text='clicks left')
48+
CSS = ChangeSet(file=os.path.join('app', 'app.css'),
49+
old_value='font-size: 18', new_value='font-size: 50',
50+
old_color=None, new_color=None)
51+
XML = ChangeSet(file=os.path.join('app', 'main-page.xml'),
52+
old_value='TAP', new_value='HIT',
53+
old_text='TAP', new_text='HIT')
3754

3855
class NGHelloWorld(object):
39-
TS = ChangeSet(file=os.path.join('src', 'app', 'item', 'item.service.ts'), old_value='Ter Stegen',
40-
new_value='Unknown')
41-
CSS = ChangeSet(file=os.path.join('src', 'app.css'), old_value='light', new_value='dark')
42-
HTML = ChangeSet(file=os.path.join('src', 'app', 'item', 'items.component.html'), old_value='"item.name"',
43-
new_value='"item.id"')
56+
TS = ChangeSet(file=os.path.join('src', 'app', 'item', 'item.service.ts'),
57+
old_value='Ter Stegen', new_value='Unknown',
58+
old_text='Ter Stegen', new_text='Unknown')
59+
CSS = ChangeSet(file=os.path.join('src', 'app.css'),
60+
old_value='light', new_value='dark',
61+
old_color=Colors.WHITE, new_color=Colors.DARK)
62+
HTML = ChangeSet(file=os.path.join('src', 'app', 'item', 'items.component.html'),
63+
old_value='"item.name"', new_value='"item.id"',
64+
old_text=None, new_text=None)
4465

4566
class MasterDetailNG(object):
4667
TS = ChangeSet(file=os.path.join('src', 'app', 'cars', 'shared', 'car.model.ts'),
47-
old_value='this._name = options.name;',
48-
new_value='this._name = "SyncTSTest";')
49-
CSS = ChangeSet(file=os.path.join('src', 'app.css'), old_value='light', new_value='dark')
50-
HTML = ChangeSet(file=os.path.join('src', 'app', 'cars', 'shared', 'car-list.component.html'),
51-
old_value='Browse',
52-
new_value='Best Car Ever!')
68+
old_value='options.name;', new_value='"SyncTSTest";',
69+
old_text='BMW 5 Series', new_text='SyncTSTest')
70+
HTML = ChangeSet(file=os.path.join('src', 'app', 'cars', 'car-list.component.html'),
71+
old_value='Browse', new_value='Best Car Ever!',
72+
old_text='Browse', new_text='Best Car Ever!')
73+
74+
# This change should make title of cars pink
75+
SCSS_ROOT_COMMON = ChangeSet(file=os.path.join('src', '_app-common.scss'),
76+
old_value='$accent-dark;', new_value='pink;',
77+
old_color=Colors.ACCENT_DARK, new_color=Colors.PINK)
78+
79+
# This change should add some red between list view items on home page
80+
SCSS_ROOT_ANDROID = ChangeSet(file=os.path.join('src', 'app.android.scss'),
81+
old_value='Android here',
82+
new_value='Android here\n.page { background-color: red;}\n',
83+
old_color=Colors.WHITE, new_color=Colors.RED_DARK)
84+
SCSS_ROOT_IOS = ChangeSet(file=os.path.join('src', 'app.ios.scss'),
85+
old_value='iOS here',
86+
new_value='iOS here\n.page { background-color: red;}\n',
87+
old_color=Colors.WHITE, new_color=Colors.RED_DARK)
88+
89+
# This change should make background of items on home page purple
90+
SCSS_NESTED_COMMON = ChangeSet(file=os.path.join('src', 'app', 'cars', '_car-list.component.scss'),
91+
old_value='$background-light;', new_value='purple;',
92+
old_color=Colors.WHITE, new_color=Colors.PURPLE)
93+
94+
# This change should make icons on home page yellow
95+
SCSS_NESTED_ANDROID = ChangeSet(file=os.path.join('src', 'app', 'cars', 'car-list.component.android.scss'),
96+
old_value='Android here',
97+
new_value='Android here\n.list-group{.list-group-item{.fa{color:yellow;}}}\n',
98+
old_color=None, new_color=Colors.YELLOW)
99+
100+
SCSS_NESTED_IOS = ChangeSet(file=os.path.join('src', 'app', 'cars', 'car-list.component.ios.scss'),
101+
old_value='iOS here',
102+
new_value='iOS here\n.list-group{.list-group-item{.fa{color:yellow;}}}\n',
103+
old_color=None, new_color=Colors.YELLOW)
53104

54105
class SharedHelloWorld(object):
55-
TS = ChangeSet(file=os.path.join('src', 'app', 'item', 'item.service.ts'), old_value='Ter Stegen',
56-
new_value='Unknown')
57-
CSS = ChangeSet(file=os.path.join('src', 'app', 'app.css'), old_value='light', new_value='dark')
58-
HTML = ChangeSet(file=os.path.join('src', 'app', 'item', 'items.component.html'), old_value='"item.name"',
59-
new_value='"item.id"')
106+
TS = ChangeSet(file=os.path.join('src', 'app', 'item', 'item.service.ts'),
107+
old_value='Ter Stegen', new_value='Unknown',
108+
old_text='Ter Stegen', new_text='Unknown')
109+
CSS = ChangeSet(file=os.path.join('src', 'app', 'app.css'),
110+
old_value='light', new_value='dark',
111+
old_color=None, new_color=None)
112+
HTML = ChangeSet(file=os.path.join('src', 'app', 'item', 'items.component.html'),
113+
old_value='"item.name"', new_value='"item.id"',
114+
old_text=None, new_text=None)

data/const.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33

44
class Colors(object):
5+
"""
6+
Notes: OpenCV color order is:
7+
0 - blue
8+
1 - green
9+
2 - red
10+
"""
511
WHITE = numpy.array([255, 255, 255]) # White color
612
DARK = numpy.array([48, 48, 48]) # Dark of default theme (on NG hello-world app).
7-
LIGHT_BLUE = numpy.array([255, 188, 48]) # Blue of TAP button on hello-world app
13+
LIGHT_BLUE = numpy.array([255, 188, 48]) # Blue of TAP button on hello-world app.
14+
ACCENT_DARK = numpy.array([255, 83, 58]) # Dark blue in pro templates.
15+
PINK = numpy.array([203, 192, 255]) # Pink (standard CSS color).
16+
RED = numpy.array([0, 0, 255]) # Red (standard CSS color).
17+
RED_DARK = numpy.array([5, 4, 229]) # A bit custom red (happens when apply red on master-detail template).
18+
PURPLE = numpy.array([128, 0, 128]) # Purple (standard CSS color).
19+
YELLOW = numpy.array([0, 255, 255]) # Yellow (standard CSS color).

0 commit comments

Comments
 (0)