1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00
trezor-firmware/tests/test_trezor.io.py
2017-12-15 01:00:00 +01:00

49 lines
1.2 KiB
Python

from common import *
from trezor import io
class TestIo(unittest.TestCase):
def test_sdcard_start(self):
sd = io.SDCard()
assert sd.present() == True
def test_sdcard_power(self):
sd = io.SDCard()
x = bytearray(8 * 512)
assert sd.capacity() == 0
assert sd.read(0, x) == False
sd.power(True)
assert sd.capacity() > 0
assert sd.read(0, x) == True
sd.power(False)
assert sd.capacity() == 0
assert sd.read(0, x) == False
def test_sdcard_read(self):
sd = io.SDCard()
x = bytearray(8 * 512)
sd.power(True)
assert sd.read(0, x) == True
sd.power(False)
assert sd.read(0, x) == False
def test_sdcard_read_write(self):
sd = io.SDCard()
r = bytearray(8 * 512)
w0 = bytearray(b'0' * (8 * 512))
w1 = bytearray(b'1' * (8 * 512))
sd.power(True)
assert sd.write(0, w0) == True
assert sd.read(0, r) == True
assert r == w0
assert sd.write(0, w1) == True
assert sd.read(0, r) == True
assert r == w1
sd.power(False)
if __name__ == '__main__':
unittest.main()