1 from pathlib
import Path
2 from itertools
import product
3 from logging
import info
5 if '' in sys
.path
: sys
.path
.remove('')
6 sys
.path
.append(str(Path(__file__
).parent
.parent
.parent
))
7 from unittest
import TestCase
8 from shutil
import rmtree
10 from os
import system
, remove
, environ
11 from os
.path
import exists
, basename
, join
13 from panda3d
.core
import Filename
14 from lib
.build
.build
import exec_cmd
, _branch
, ver
17 class FunctionalTests(TestCase
):
22 str(Path
.home()) + '/.local/share/pmachines/tests/functional/',
23 str(Path
.home()) + '/.var/app/it.ya2.Pmachines/data/pmachines/tests/functional/',
24 str(Path
.home()) + '/.wine/drive_c/users/flavio/AppData/Local/pmachines/tests/functional/']
26 rmtree(path
, ignore_errors
=True)
28 Filename().get_user_appdata_directory(),
29 '/home/flavio/.var/app/it.ya2.Pmachines/data',
30 '/home/flavio/.wine/drive_c/users/flavio/AppData']
32 'pmachines/options.ini',
33 'pmachines/obs_version.txt']
34 for dir_file
in product(dirs
, files
):
35 _file
= join(*dir_file
)
38 info('%s removed' % _file
)
40 info('%s does not exist' % _file
)
41 system('pkill -f "pmachines.exe"')
44 system('xdotool key shift')
54 path
= 'pmachines/tests/functional_ref_%s/*.png' % _branch()
55 files
= glob(join(Filename().get_user_appdata_directory(), path
))
56 self
.assertGreater(len(files
), 1)
58 def __similar_images(self
, ref_img
, tst_img
):
59 cmd
= 'magick compare -metric NCC %s %s diff.png' % (ref_img
, tst_img
)
61 if exists('diff.png'): remove('diff.png')
62 print('compare %s %s: %s' % (ref_img
, tst_img
, res
))
63 return float(res
) > .64
65 def __test_template(self
, cmd
, path
):
66 if environ
.get('FUNCTIONAL') != '1':
67 self
.skipTest('skipped functional tests')
70 system('amixer sset Master 0%')
72 self
.assertEqual(ret
, 0)
73 files
= glob('tests/functional_ref/*.png')
75 self
.assertTrue(exists(path
+ basename(fname
)))
77 self
.__similar
_images
(
78 fname
, path
+ basename(fname
)))
80 # def test_code(self):
82 # self.__test_template(
83 # '~/venv/bin/python main.py --functional-test 1 ; '
84 # '~/venv/bin/python main.py --functional-test 2',
85 # str(Path.home()) + '/.local/share/pmachines/tests/functional/')
87 # def test_appimage(self):
88 # info('test_appimage')
89 # bld_branch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[_branch()]
90 # bld_branch = '' if bld_branch == 'stable' else ('-' + bld_branch)
91 # self.__test_template(
92 # './dist/Pmachines%s-x86_64.AppImage --functional-test 1 ;'
93 # './dist/Pmachines%s-x86_64.AppImage --functional-test 2' % (bld_branch, bld_branch),
94 # str(Path.home()) + '/.local/share/pmachines/tests/functional/')
96 # def test_flatpak(self):
97 # info('test_flatpak')
98 # if environ.get('FUNCTIONALPOST') != '1':
99 # self.skipTest('skipped functional-post tests')
100 # bld_branch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[_branch()]
101 # cmd = 'flatpak update -y it.ya2.Pmachines//%s' % bld_branch
102 # info('executing: %s' % cmd)
104 # info('executed: %s' % cmd)
105 # self.__test_template(
106 # 'flatpak run it.ya2.Pmachines//%s --functional-test 1 ;'
107 # 'flatpak run it.ya2.Pmachines//%s --functional-test 2' % (bld_branch, bld_branch),
108 # str(Path.home()) + '/.var/app/it.ya2.Pmachines/data/pmachines/tests/functional/')
110 # def __update_itchio(self):
111 # system('/home/flavio/.itch/itch')
113 # system('xdotool mousemove 1280 620')
115 # system('xdotool click 1')
117 # system('killall itch')
119 # def test_itchio(self):
120 # info('test_itchio')
121 # if environ.get('FUNCTIONALPOST') != '1':
122 # self.skipTest('skipped functional-post tests')
123 # if _branch() != 'master':
125 # self.__update_itchio()
126 # self.__test_template(
127 # '/home/flavio/.config/itch/apps/pmachines/pmachines --functional-test 1 ;'
128 # '/home/flavio/.config/itch/apps/pmachines/pmachines --functional-test 2',
129 # str(Path.home()) + '/.local/share/pmachines/tests/functional/')
131 # def test_windows(self):
132 # info('test_windows')
133 # system('pkill -f "pmachines.exe"')
134 # abspath = str(Path(__file__).parent.parent) + '/build/win_amd64/pmachines.exe'
135 # self.__test_template(
136 # 'timeout 720s wine %s --functional-test 1 ; '
137 # 'timeout 720s wine %s --functional-test 2' % (abspath, abspath),
138 # str(Path.home()) + '/.wine/drive_c/users/flavio/AppData/Local/pmachines/tests/functional/')
140 # def test_versions(self):
141 # info('test_versions')
142 # if environ.get('FUNCTIONAL') != '1':
143 # self.skipTest('skipped functional tests')
144 # bld_branch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[_branch()]
145 # with open('/home/flavio/pmachines_builder/last_bld.txt') as f:
146 # lines = f.readlines()
148 # if line.strip().split()[0] == _branch():
149 # commit = line.strip().split()[1][:7]
151 # if _branch() == 'stable':
152 # with open('/home/flavio/pmachines_builder/pmachines/assets/version.txt') as fver:
153 # _ver = fver.read().strip() + '-'
154 # exp = '%s-%s' % (_ver, commit)
156 # ('./build/manylinux1_x86_64/pmachines --version', str(Filename.get_user_appdata_directory()) + '/pmachines/obs_version.txt'),
157 # ('./dist/Pmachines-%s-x86_64.AppImage --version' % bld_branch, str(Filename.get_user_appdata_directory()) + '/pmachines/obs_version.txt'),
158 # ('timeout 720s wine ./build/win_amd64/pmachines.exe --version', '/home/flavio/.wine/drive_c/users/flavio/AppData/Local/pmachines/obs_version.txt')
160 # if environ.get('FUNCTIONALPOST') == '1':
161 # if _branch() == 'master':
162 # self.__update_itchio()
163 # cmds += [('/home/flavio/.config/itch/apps/pmachines/pmachines --version', str(Filename.get_user_appdata_directory()) + '/pmachines/obs_version.txt')]
164 # cmds += [('flatpak run it.ya2.Pmachines//%s --version' % bld_branch, '/home/flavio/.var/app/it.ya2.Pmachines/data/pmachines/obs_version.txt')]
165 # system('flatpak update -y it.ya2.Pmachines//%s' % bld_branch)
169 # info('launching %s' % cmd[0])
171 # with open(cmd[1]) as f:
172 # obs = f.read().strip()
173 # self.assertEqual(obs, exp)