initial test fixing

This commit is contained in:
avirgovi 2022-05-13 14:05:54 +02:00
parent 50c541c080
commit 69843b9f69
8 changed files with 19 additions and 16 deletions

View File

@ -3,6 +3,9 @@
None of this code ships on the product itself, but it does get used for testing purposes.
## Dependencies
* 7z
## Background
- pytest is used to track test cases and fixtures, etc

View File

@ -1,6 +1,6 @@
# (c) Copyright 2020 by Coinkite Inc. This file is covered by license found in COPYING-CC.
#
import pytest, glob, time, sys, random, re
import pytest, glob, time, sys, random, re, ndef
from pprint import pprint
from ckcc.protocol import CCProtocolPacker, CCProtoError
from helpers import B2A, U2SAT, prandom
@ -418,7 +418,10 @@ def qr_quality_check():
scale=3
rv = Image.new('RGB', (w*scale, ((h*scale)+TH)*count), color=(64,64,64))
y = 0
fnt = ImageFont.truetype('Courier', size=10)
try:
fnt = ImageFont.truetype('Courier', size=10)
except:
fnt = ImageFont.load_default()
dr = ImageDraw.Draw(rv)
mw = int((w*scale) / dr.textsize('M', fnt)[0])
@ -866,7 +869,6 @@ def decode_with_bitcoind(bitcoind):
def doit(raw_txn):
# verify our understanding of a TXN (and esp its outputs) matches
# the same values as what bitcoind generates
try:
return bitcoind.decoderawtransaction(B2A(raw_txn))
except ConnectionResetError:
@ -947,7 +949,6 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke
# like "try_sign" but use "air gapped" file transfer via microSD
def doit(f_or_data, accept=True, finalize=False, accept_ms_import=False, complete=False, encoding='binary', del_after=0):
if f_or_data[0:5] == b'psbt\xff':
ip = f_or_data
filename = 'memory'
@ -965,7 +966,7 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke
pat = microsd_path(psbtname+'*.psbt')
for f in glob(pat):
assert 'psbt' in f
os.unlink(f)
os.remove(f)
if encoding == 'hex':
ip = b2a_hex(ip)
@ -986,8 +987,7 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke
if 'Choose PSBT file' in story:
need_keypress('y')
time.sleep(.1)
pick_menu_item(psbtname+'.psbt')
pick_menu_item(psbtname+'.psbt')
time.sleep(.1)
@ -1305,7 +1305,7 @@ def nfc_write(request, only_mk4):
@pytest.fixture()
def nfc_read_json(nfc_read):
def doit():
import ndef, json
import json
got = list(ndef.message_decoder(nfc_read()))
assert len(got) == 1
got = got[0]
@ -1317,7 +1317,6 @@ def nfc_read_json(nfc_read):
@pytest.fixture()
def nfc_read_text(nfc_read):
def doit():
import ndef
got = list(ndef.message_decoder(nfc_read()))
assert len(got) == 1
got = got[0]

View File

@ -98,7 +98,7 @@ async def test_7z():
if had_policy:
from hsm import POLICY_FNAME
uos.unlink(POLICY_FNAME)
uos.remove(POLICY_FNAME)
assert not hsm.hsm_policy_available()
with SFFile(0, ll) as fd:

View File

@ -13,7 +13,8 @@ zbar-py==1.0.4
# NFC and NDEF handling
nfcpy==1.0.3
ndef==0.2
# commentt out below dependency 'ndef==0.2' if on debian based OS
#ndef==0.2
# optional, and only helpful if you have a desktop NFC-V capable reader
pyscard==2.0.2

View File

@ -464,7 +464,7 @@ def test_export_public_txt(dev, cap_menu, pick_menu_item, goto_home, cap_story,
time.sleep(0.1)
title, story = cap_story()
assert 'Saves a text file to' in story
assert 'Saves a text file' in story
need_keypress('y')
time.sleep(0.1)

View File

@ -57,7 +57,7 @@ def hsm_reset(dev, sim_exec):
# make sure we can setup an HSM now; often need to restart simulator tho
# clear defined config
cmd = 'import uos, hsm; uos.unlink(hsm.POLICY_FNAME)'
cmd = 'import uos, hsm; uos.remove(hsm.POLICY_FNAME)'
sim_exec(cmd)
# reset HSM code, to clear previous HSM setup
@ -74,7 +74,7 @@ def hsm_reset(dev, sim_exec):
yield doit
try:
cmd = 'import uos, hsm; uos.unlink(hsm.POLICY_FNAME)'
cmd = 'import uos, hsm; uos.remove(hsm.POLICY_FNAME)'
sim_exec(cmd)
except:
pass

View File

@ -5,7 +5,7 @@
# - needs "dieharder" installed, see
# <https://webhome.phy.duke.edu/~rgb/General/dieharder.php>
# - on mac: "brew install dieharder"
#
# - on ubuntu20: "sudo apt-get install dieharder"
import pytest, subprocess, os
from helpers import B2A

View File

@ -14,7 +14,7 @@ def open(name, maxver=10, extra=()):
except KeyError:
pass
def libs():
if sys.platform == "linux":
if sys.platform in ["linux", "linux2", "coldcard-unix"]:
yield '%s.so' % name
for i in range(maxver, -1, -1):
yield '%s.so.%u' % (name, i)