forked from CareDailyAI/botlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytest
executable file
·65 lines (52 loc) · 2.81 KB
/
pytest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# encoding: utf-8
# USAGE: ./pytest --core ../botlab-private/
import importlib
import sys
import os
import shutil
import pytest
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
parser = ArgumentParser(description="Bot PyTest Tool", formatter_class=RawDescriptionHelpFormatter, add_help=False)
developer_group = parser.add_argument_group("Bot Configuration")
developer_group.add_argument("--core", dest="core_directory", help="For repository structures that separate a shared core bot repository from a private proprietary repository, this is the absolute path to the core bot repository.")
developer_group.add_argument("-m", "--mut", dest="mut", action="append", help="Specific microservice packages to test, you can append more than one")
developer_group.add_argument("-b", "--bundle", dest="bundle_id", help="Specific microservices bundle (e.g., app) to test the microservice within. Default to com.ppc.Tests")
args = parser.parse_args()
print("args: {}".format(args))
core = os.getcwd()
if args.core_directory is not None:
core = args.core_directory
print("Using $BOTLAB_CORE = {}".format(core))
# Load the botengine.
shutil.copy(os.path.join('./', 'botengine'), 'botengine.py')
botengine = importlib.import_module('botengine')
# Generate the bot
botname = "com.ppc.Tests"
if args.bundle_id is not None:
botname = args.bundle_id
base_path = os.path.join(os.getcwd(), "." + botname)
print("Using base_path = {}".format(base_path))
botengine._merge_redirects(os.path.join(core, botname), base_path, botname, core_directory=core)
# Here we're going to overwrite the set of microservices in the bot with ALL the available microservice packages.
# This is because when we load up ISM data environments from other bots, we need to be able to unpickle objects and land on files that exist.
for original_microservice_dir in os.listdir(os.path.join(os.getcwd(), "." + botname, 'intelligence')):
if os.path.isdir(os.path.join(os.getcwd(), "." + botname, 'intelligence', original_microservice_dir)):
if original_microservice_dir not in os.listdir(os.path.join(base_path, 'intelligence')):
shutil.copytree(os.path.join(os.getcwd(), "." + botname, 'intelligence', original_microservice_dir), os.path.join(base_path, 'intelligence', original_microservice_dir))
extras = []
if args.mut is not None:
for mut in args.mut:
print("MUT: {}".format(mut))
extras += ['-k', mut]
# Delete the 'botengine.py' module which was temporarily created for this task
try:
os.remove('botengine.py')
except:
pass
# Copy the botengine pytest stubs into this directory
botengine_destination = os.path.join(core, base_path, 'botengine_pytest.py')
shutil.copyfile('./botengine_pytest.py', botengine_destination)
# Run pytest
pytest.main(['-q', base_path, '-v', '-s'] + extras)