def test_get_connection_details_device_exception(): """ Test if get_connection_details raises a DeviceException when trying to find a non-existent device. """ with pytest.raises(DeviceException): get_connection_details(vendor='vendor', model='model')
def test_get_connection_details_device_exception(self): """ Test 'get_connection_details' raises a DeviceException with an appropriate error message when trying to find a non-existent device. """ with self.assertRaises(DeviceException) as exc: get_connection_details(vendor="non-existent-vendor", model="non-existent-model") exc_msg_parts = ( 'Device "non-existent-vendor non-existent-model" not found.', 'No "non-existent-vendor" devices were found.', ) self.assertEqual(str(exc.exception), "\n".join(exc_msg_parts))
def device_not_connected(): """ Helper - check if testing device not connected :returns bool """ try: get_connection_details(vendor=DEVICE_VENDOR, model=DEVICE_MODEL) except DeviceException: device_not_connected = True else: device_not_connected = False finally: return device_not_connected
def test_get_connection_details_device_exception_message(self): """ Test 'get_connection_details' raises a DeviceException and the provided error message lists all vendor devices when trying to find a non-existent model. """ with self.assertRaises(DeviceException) as exc: get_connection_details(vendor="linux", model="non-existent-model") exc_msg_parts = ( 'Device "linux non-existent-model" not found.', 'Following "linux" devices were found:', "Linux Foundation 2.0 root hub", "Linux Foundation 3.0 root hub", ) self.assertEqual(str(exc.exception), "\n".join(exc_msg_parts))
def test_get_mtp_details(self): """ Test 'get_mtp_details' returns a valid MTP url gvfs path. """ usb_bus, device = get_connection_details(vendor="linux", model="root") mtp_details = get_mtp_details(usb_bus, device) self.assertIsInstance(mtp_details, tuple) for mtp_detail in mtp_details: self.assertIn(device, mtp_detail) self.assertIn(usb_bus, mtp_detail)
def test_get_connection_details_multiple_devices(self): """ Test 'get_connection_details' is able to find the given device in case of multiple devices from the same vendor (i.e. it doesn't pick up the first device for a certain vendor). """ connection_details = get_connection_details(vendor="test_vendor", model="test_model3") self.assertIsInstance(connection_details, tuple) self.assertEqual(connection_details[0], "002") self.assertEqual(connection_details[1], "003")
def mtp(): """ Fixture - get MTP path to the testing device :returns str """ usb_bus, device = get_connection_details(vendor=DEVICE_VENDOR, model=DEVICE_MODEL) mtp_details = get_mtp_details(usb_bus, device) return mtp_details
def main(): args = parser.parse_args() usb_bus, device = find_device.get_connection_details(vendor=args.vendor, model=args.model) mtp_details = find_device.get_mtp_details(usb_bus, device) sync = Sync( mtp_details=mtp_details, source=args.source, destination=args.destination, unmatched=args.unmatched, overwrite_existing=args.overwrite, verbose=args.verbose, ignore_file_types=args.ignore_file_type, ) sync.set_source_abs() sync.set_destination_abs() sync.sync()
def run(args): """ Run pysyncdroid. :argument args: command line arguments namespace :type args: object """ try: usb_bus_id, device_id = get_connection_details(args.vendor, args.model) mtp_details = get_mtp_details(usb_bus_id, device_id) except DeviceException as exc: return str(exc) try: sources, destinations = parse_sync_info(args) except (argparse.ArgumentError, MappingFileException) as exc: return str(exc) for source, destination in zip(sources, destinations): source = source.strip() destination = destination.strip() sync = Sync( mtp_details=mtp_details, source=source, destination=destination, verbose=args.verbose, unmatched=args.unmatched, overwrite_existing=args.overwrite, ignore_file_types=args.ignore_file_type, ) sync.set_source_abs() sync.set_destination_abs() sync.sync()
def get_device(): """ Fixture - get details for a 'Linux Foundation 2.0 root hub' device. """ return get_connection_details(vendor='linux', model='root')