on xenial help sign in
Add import test
commit1a33af9608402551312164134ceac3f330882a96 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateFri 5 Aug 2016, 21:48 (10 years ago) parent2325677
2 files changed+46−1
qml/Launcher/LauncherPanel.qml+1−1 tests/imports/check_imports.py+45
qml/Launcher/LauncherPanel.qml+1−1
@@ -19,7 +19,7 @@ import Ubuntu.Components 1.3
1919import Unity.Launcher 0.1
2020import Ubuntu.Components.Popups 1.3
2121import "../Components/ListItems"
22−import "../Components/"
22+import "../Components"
2323
2424Rectangle {
2525 id: root
tests/imports/check_imports.py+45
@@ -81,6 +81,48 @@ def scan_for_bad_import(file_path, all_pat, good_pats):
8181 print("%s: bad import version in multiple lines" % file_path)
8282 return bool(errors)
8383
84+# Flickable matches
85+flickable_pat = re.compile(r'.*\ Flickable {')
86+listview_pat = re.compile(r'.*\ ListView {')
87+gridview_pat = re.compile(r'.*\ GridView {')
88+flickable_pats = [flickable_pat, listview_pat, gridview_pat]
89+unity_components_pat = re.compile(r'.*import ".*Components"')
90+components_path = re.compile(r'.*qml/Components.*')
91+
92+def scan_for_flickable_imports(file_path, component_pats, qtquick_pat, uitk_pat):
93+ errors = []
94+ with open(file_path, 'rt', encoding='utf-8') as ifile, open(file_path, 'rt', encoding='utf-8') as i2file:
95+ flickable_found = False
96+ for lino, line in enumerate(ifile, start=1):
97+ for component_pat in component_pats:
98+ if component_pat.match(line):
99+ flickable_found = True
100+ if flickable_found:
101+ qtquick_found = False
102+ uitk_found = False
103+ for lino, line in enumerate(i2file, start=1):
104+ if not qtquick_found and qtquick_pat.match(line):
105+ qtquick_found = True
106+ if uitk_pat.match(line):
107+ uitk_found = True
108+ if not qtquick_found:
109+ errors.append(lino)
110+ else:
111+ return
112+ if not uitk_found:
113+ errors.append(lino)
114+ if 0 < len(errors) <= 10:
115+ if len(errors) > 1:
116+ plural = 's'
117+ else:
118+ plural = ''
119+ print(
120+ "%s: bad import version in line%s %s" % (
121+ file_path, plural, ", ".join((str(i) for i in errors))))
122+ elif errors:
123+ print("%s: bad import version in multiple lines" % file_path)
124+ return bool(errors)
125+
84126# Parse args
85127
86128parser = argparse.ArgumentParser(
@@ -116,6 +158,9 @@ try:
116158 found_bad_import = True
117159 if scan_for_bad_import(path, ubuntu_components_pat, [ubuntu_good_components_pat]):
118160 found_bad_import = True
161+ if not components_path.match(path):
162+ if scan_for_flickable_imports(path, flickable_pats, quick_good_pat, unity_components_pat):
163+ found_bad_import = True
119164
120165except OSError as e:
121166 error("cannot create file list for \"" + dir + "\": " + e.strerror)