tests: start moving common functions to top level

pull/520/head
matejcik 5 years ago
parent b3c58e4a17
commit b7ba306a46

@ -14,6 +14,7 @@
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from collections import defaultdict
import os
import subprocess
import tempfile
@ -25,6 +26,47 @@ from trezorlib.transport import TransportException, get_transport
BINDIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators"
ENV = {"SDL_VIDEODRIVER": "dummy"}
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../"
LOCAL_BUILDS = {
"core": ROOT + "core/build/unix/micropython",
"legacy": ROOT + "legacy/firmware/trezor.elf",
}
BIN_DIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators"
def check_version(tag, ver_emu):
if tag.startswith("v") and len(tag.split(".")) == 3:
assert tag == "v" + ".".join(["%d" % i for i in ver_emu])
def check_file(gen, tag):
if tag.startswith("/"):
filename = tag
else:
filename = "%s/trezor-emu-%s-%s" % (BIN_DIR, gen, tag)
if not os.path.exists(filename):
raise ValueError(filename + " not found. Do not forget to build firmware.")
def get_tags():
files = os.listdir(BIN_DIR)
if not files:
raise ValueError(
"No files found. Use download_emulators.sh to download emulators."
)
result = defaultdict(list)
for f in sorted(files):
try:
_, _, gen, tag = f.split("-", maxsplit=3)
result[gen].append(tag)
except ValueError:
pass
return result
ALL_TAGS = get_tags()
class EmulatorWrapper:
def __init__(self, gen, tag, storage=None):

@ -21,7 +21,7 @@ import os.path
from trezorlib import coins
from trezorlib.tx_api import json_to_tx
CACHE_PATH = os.path.join(os.path.dirname(__file__), "..", "txcache")
CACHE_PATH = os.path.join(os.path.dirname(__file__), "txcache")
def tx_cache(coin_name, allow_fetch=True):

@ -25,10 +25,7 @@ from trezorlib.tools import H_
MINIMUM_FIRMWARE_VERSION["1"] = (1, 0, 0)
MINIMUM_FIRMWARE_VERSION["T"] = (2, 0, 0)
try:
from .emulator_wrapper import EmulatorWrapper
except ImportError:
pass
from ..emulators import EmulatorWrapper, ALL_TAGS, LOCAL_BUILDS
# **** COMMON DEFINITIONS ****
@ -39,47 +36,6 @@ LABEL = "test"
LANGUAGE = "english"
STRENGTH = 128
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../../"
LOCAL_BUILDS = {
"core": ROOT + "core/build/unix/micropython",
"legacy": ROOT + "legacy/firmware/trezor.elf",
}
BIN_DIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators"
def check_version(tag, ver_emu):
if tag.startswith("v") and len(tag.split(".")) == 3:
assert tag == "v" + ".".join(["%d" % i for i in ver_emu])
def check_file(gen, tag):
if tag.startswith("/"):
filename = tag
else:
filename = "%s/trezor-emu-%s-%s" % (BIN_DIR, gen, tag)
if not os.path.exists(filename):
raise ValueError(filename + " not found. Do not forget to build firmware.")
def get_tags():
files = os.listdir(BIN_DIR)
if not files:
raise ValueError(
"No files found. Use download_emulators.sh to download emulators."
)
result = defaultdict(list)
for f in sorted(files):
try:
_, _, gen, tag = f.split("-", maxsplit=3)
result[gen].append(tag)
except ValueError:
pass
return result
ALL_TAGS = get_tags()
def for_all(*args, minimum_version=(1, 0, 0)):
if not args:

Loading…
Cancel
Save