from panda3d.core import load_prc_file_data
load_prc_file_data('', 'window-type none')
import datetime
+from pathlib import Path
from time import sleep
from os import getcwd, system
from xmlrpc.client import ServerProxy
-from logging import debug, info
from pathlib import Path
from shutil import rmtree
from os import makedirs
from ya2.build.build import _branch
import asyncio
import xmlrpc
+from logging import basicConfig, debug, info, INFO, DEBUG, getLogger, StreamHandler, Formatter, FileHandler
+
+
+basicConfig(level=DEBUG, format='(evt-test) %(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
+getLogger().setLevel(DEBUG) # it doesn't work otherwise
class FunctionalTest:
def __init__(self, idx, offset):
debug('creating FunctionalTest (%s)' % id(self))
super().__init__()
+
+ timestamp = datetime.datetime.now().strftime('%y%m%d%H%M%S')
+ logFormatter = Formatter('%(asctime)s.%(msecs)03d %(message)s', datefmt='%H:%M:%S')
+ path = str(Path.home()) + '/.local/share/pmachines/logs/evt/'
+ if not exists(path):
+ makedirs(path)
+ lpath = path + 'evt_%s.log' % timestamp
+ fileHandler = FileHandler(lpath)
+ fileHandler.setFormatter(logFormatter)
+ getLogger().addHandler(fileHandler)
+
info('test idx: %s' % idx)
self._offset = offset
sleep(12)
print('compare %s %s: %s' % (ref_img, tst_img, res))
return float(res) > .8
- def __test_template(self, app_cmd, test1_cmd, test2_cmd, path):
+ def __test_template(self, app_cmd, test_cmds, path):
if environ.get('FUNCTIONAL') != '1':
self.skipTest('skipped functional tests')
self.__clean()
#ret = system(cmd)
#proc = run(cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=check)
#return proc.stdout.strip() + proc.stderr.strip()
- info('launching ' + app_cmd)
- print('launching ' + app_cmd)
- p_app = Popen(app_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
- sleep(8)
- info('launching ' + test1_cmd)
- print('launching ' + test1_cmd)
- p_test = Popen(test1_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
- p_app_out, p_app_err = p_app.communicate()
- t_out, t_err = p_test.communicate()
- info('output (%s): %s' % (app_cmd, p_app_out))
- info('error (%s): %s' % (app_cmd, p_app_err))
- info('output (%s): %s' % (test1_cmd, t_out))
- info('error (%s): %s' % (test1_cmd, t_err))
- print('output (%s): %s' % (app_cmd, p_app_out))
- print('error (%s): %s' % (app_cmd, p_app_err))
- print('output (%s): %s' % (test1_cmd, t_out))
- print('error (%s): %s' % (test1_cmd, t_err))
- self.assertEqual(p_app.returncode, 0, 'error while executing ' + app_cmd)
- self.assertEqual(p_test.returncode, 0, 'error while executing ' + test1_cmd)
- sleep(12)
- info('launching ' + app_cmd)
- print('launching ' + app_cmd)
- p_app = Popen(app_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
- sleep(8)
- info('launching ' + test2_cmd)
- print('launching ' + test2_cmd)
- p_test = Popen(test2_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
- p_app_out, p_app_err = p_app.communicate()
- t_out, t_err = p_test.communicate()
- info('output (%s): %s' % (app_cmd, p_app_out))
- info('error (%s): %s' % (app_cmd, p_app_err))
- info('output (%s): %s' % (test2_cmd, t_out))
- info('error (%s): %s' % (test2_cmd, t_err))
- print('output (%s): %s' % (app_cmd, p_app_out))
- print('error (%s): %s' % (app_cmd, p_app_err))
- print('output (%s): %s' % (test2_cmd, t_out))
- print('error (%s): %s' % (test2_cmd, t_err))
- self.assertEqual(p_app.returncode, 0, 'error while executing ' + app_cmd)
- self.assertEqual(p_test.returncode, 0, 'error while executing ' + test2_cmd)
+ for test_cmd in test_cmds:
+ sleep(8)
+ info('launching ' + app_cmd)
+ print('launching ' + app_cmd)
+ p_app = Popen(app_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
+ sleep(30)
+ info('launching ' + test_cmd)
+ print('launching ' + test_cmd)
+ p_test = Popen(test_cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
+ p_app_out, p_app_err = p_app.communicate()
+ t_out, t_err = p_test.communicate()
+ info('output (%s): %s' % (app_cmd, p_app_out))
+ info('error (%s): %s' % (app_cmd, p_app_err))
+ info('output (%s): %s' % (test_cmd, t_out))
+ info('error (%s): %s' % (test_cmd, t_err))
+ print('output (%s): %s' % (app_cmd, p_app_out))
+ print('error (%s): %s' % (app_cmd, p_app_err))
+ print('output (%s): %s' % (test_cmd, t_out))
+ print('error (%s): %s' % (test_cmd, t_err))
+ self.assertEqual(p_app.returncode, 0, 'error while executing ' + app_cmd)
+ self.assertEqual(p_test.returncode, 0, 'error while executing ' + test_cmd)
files = glob(str(Path.home()) + '/.local/share/pmachines/tests/functional_ref_%s/*.png' % _branch())
self.assertGreater(len(files), 1)
for fname in files:
def test_code(self):
info('test_code')
self.__test_template(
- 'timeout 7200s ~/venv/bin/python main.py --functional-test',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2',
+ '/home/flavio/venv/bin/python main.py --functional-test',
+ ['/home/flavio/venv/bin/python -m tests.functional_test.py 1',
+ 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2'],
str(Path.home()) + '/.local/share/pmachines/tests/functional/')
def test_appimage(self):
bld_branch = '' if bld_branch == 'stable' else ('-' + bld_branch)
self.__test_template(
'timeout 7200s ./dist/Pmachines%s-x86_64.AppImage --functional-test' % bld_branch,
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2',
+ ['timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
+ 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2'],
str(Path.home()) + '/.local/share/pmachines/tests/functional/')
# def test_flatpak(self):
self.__update_itchio()
self.__test_template(
'timeout 7200s /home/flavio/.config/itch/apps/pmachines/pmachines --functional-test',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2',
+ ['timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
+ 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2'],
str(Path.home()) + '/.local/share/pmachines/tests/functional/')
def test_windows(self):
abspath = str(Path(__file__).parent.parent) + '/build/win_amd64/pmachines.exe'
self.__test_template(
'timeout 7200s wine %s --functional-test' % abspath,
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
- 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2',
+ ['timeout 7200s ~/venv/bin/python -m tests.functional_test.py 1',
+ 'timeout 7200s ~/venv/bin/python -m tests.functional_test.py 2'],
str(Path.home()) + '/.wine/drive_c/users/flavio/AppData/Local/pmachines/tests/functional/')
def test_versions(self):