def test_mount_unmount(self): fatfs.mkfs() self.assertFalse(fatfs.is_mounted()) fatfs.mount() self.assertTrue(fatfs.is_mounted()) fatfs.mount() self.assertTrue(fatfs.is_mounted()) fatfs.unmount() self.assertFalse(fatfs.is_mounted())
def __enter__(self) -> None: try: if self.counter <= 0: self.counter = 0 sdcard.power_on() if self.mounted: fatfs.mount() self.counter += 1 except Exception: self._deinit_instance() raise
def test_no_filesystem(self): # trash FAT table sdcard.write(0, bytes([0xFF] * sdcard.BLOCK_SIZE)) self.assertFalse(fatfs.is_mounted()) try: fatfs.mount() self.fail("should have raised") except OSError as e: self.assertEqual(e.args[0], 19) # ENODEV self.assertFalse(fatfs.is_mounted())
def test_sd_power(self): sdcard.power_off() self.assertFalse(fatfs.is_mounted()) self.assertRaises(fatfs.FatFSError, fatfs.mount) sdcard.power_on() self.assertFalse(fatfs.is_mounted()) fatfs.mkfs() fatfs.mount() self.assertTrue(fatfs.is_mounted()) sdcard.power_off() self.assertFalse(fatfs.is_mounted())
def test_no_filesystem(self): # trash FAT table sdcard.write(0, bytes([0xFF] * sdcard.BLOCK_SIZE)) self.assertFalse(fatfs.is_mounted()) try: fatfs.mount() self.fail("should have raised") except fatfs.FatFSError as e: self.assertIsInstance(e, fatfs.NoFilesystem) # check that the proper error code is set on the NoFilesystem subclass self.assertEqual(e.args[0], fatfs.FR_NO_FILESYSTEM) self.assertFalse(fatfs.is_mounted())
def test_mounted(self): fatfs.mkfs() fatfs.mount() self.assertTrue(fatfs.is_mounted()) for name, call in self.MOUNTED_METHODS: function = getattr(fatfs, name) function(*call) for name, call in self.UNMOUNTED_METHODS: function = getattr(fatfs, name) try: function(*call) self.fail("should have raised") except fatfs.FatFSError as e: self.assertEqual(e.args[0], fatfs.FR_LOCKED)
def setUp(self): sdcard.power_on() fatfs.mkfs() fatfs.mount()