mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-09 17:10:17 +00:00
e073e619c9
isort set to skip the first necessary "from common import *" line. A better solution would be to get rid of the need of this import in the future. [no changelog]
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from common import * # isort:skip
|
|
|
|
from trezor import io, utils
|
|
|
|
|
|
class TestTrezorIoSdcard(unittest.TestCase):
|
|
def test_start(self):
|
|
self.assertTrue(io.sdcard.is_present())
|
|
|
|
def test_power(self):
|
|
x = bytearray(8 * 512)
|
|
self.assertEqual(io.sdcard.capacity(), 0)
|
|
with self.assertRaises(OSError):
|
|
io.sdcard.read(0, x)
|
|
io.sdcard.power_on()
|
|
self.assertTrue(io.sdcard.capacity() > 0)
|
|
io.sdcard.read(0, x)
|
|
io.sdcard.power_off()
|
|
self.assertEqual(io.sdcard.capacity(), 0)
|
|
with self.assertRaises(OSError):
|
|
io.sdcard.read(0, x)
|
|
|
|
def test_read(self):
|
|
x = bytearray(8 * 512)
|
|
io.sdcard.power_on()
|
|
io.sdcard.read(0, x)
|
|
io.sdcard.power_off()
|
|
with self.assertRaises(OSError):
|
|
io.sdcard.read(0, x)
|
|
|
|
def test_read_write(self):
|
|
r = bytearray(8 * 512)
|
|
w0 = bytearray(b"0" * (8 * 512))
|
|
w1 = bytearray(b"1" * (8 * 512))
|
|
io.sdcard.power_on()
|
|
io.sdcard.write(0, w0)
|
|
io.sdcard.read(0, r)
|
|
self.assertEqual(r, w0)
|
|
io.sdcard.write(0, w1)
|
|
io.sdcard.read(0, r)
|
|
self.assertEqual(r, w1)
|
|
io.sdcard.power_off()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if utils.USE_SD_CARD:
|
|
unittest.main()
|