def test_multiple_device_info_single(self): """ If a MultipleDeviceInfo has only one child, get_device() should just return the single child. """ self.build_config_file( "foo.py", """from miro.devices import DeviceInfo, MultipleDeviceInfo defaults = { "audio_conversion": "mp3", "container_types": "mp3 isom".split(), "audio_types": "mp3 aac".split(), "video_types": ["h264"], "mount_instructions": "Mount Instructions\\nOver multiple lines", "video_path": u"Video", "audio_path": u"Audio", } target1 = DeviceInfo("Target1", vendor_id=0x890a, product_id=0xbcde, video_conversion="mp4", **defaults) multiple = MultipleDeviceInfo('Foo', [target1]) devices = [multiple] """) dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, '*.py')) device = dm.get_device('Foo') self.assertFalse(device.has_multiple_devices) self.assertEqual(device.name, "Target1") self.assertEqual(device.device_name, "Foo")
def test_multiple_device_gets_data_from_first_child(self): """ If a MultipleDeviceInfo object is created without all the appropriate data, it will grab it from its first child. """ self.build_config_file( "foo.py", """from miro.devices import DeviceInfo, MultipleDeviceInfo defaults = { "audio_conversion": "mp3", "container_types": "mp3 isom".split(), "audio_types": "mp3 aac".split(), "video_types": ["h264"], "mount_instructions": "Mount Instructions\\nOver multiple lines", "video_path": u"Video", "audio_path": u"Audio", } target1 = DeviceInfo("Target1", vendor_id=0x890a, product_id=0xbcde, video_conversion="mp4", **defaults) target2 = DeviceInfo("Target2") multiple = MultipleDeviceInfo('Foo', [target1, target2]) devices = [multiple] """) dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, '*.py')) device = dm.get_device('Foo') self.assertTrue(device.has_multiple_devices) self.assertEqual(device.video_conversion, "mp4")
def setUp(self): self.setup_log_filter() self.tempdir = tempfile.mkdtemp() if not os.path.exists(self.tempdir): os.makedirs(self.tempdir) self.setup_downloader_log() models.initialize() app.in_unit_tests = True app.device_manager = devices.DeviceManager() models.Item._path_count_tracker.reset() testobjects.test_started(self) # Tweak Item to allow us to make up fake paths for FileItems models.Item._allow_nonexistent_paths = True # setup the deleted file checker item.setup_deleted_checker() item.start_deleted_checker() # Skip worker proccess for feedparser feed._RUN_FEED_PARSER_INLINE = True signals.system.connect('new-dialog', self.handle_new_dialog) # reload config and initialize it to temprary config.load_temporary() self.setup_config_watcher() self.platform = app.config.get(prefs.APP_PLATFORM) self.set_temp_support_directory() # for the unittests, both the database code and any UI code should run # in the main thread. threadcheck.set_eventloop_thread(threading.currentThread()) threadcheck.set_ui_thread(threading.currentThread()) self.raise_db_load_errors = True app.db = None self.allow_db_upgrade_error_dialog = False self.reload_database() self.setup_new_item_info_cache() self.setup_dummy_message_handlers() item.setup_metadata_manager(self.tempdir) searchengines._engines = [ searchengines.SearchEngineInfo(u"all", u"Search All", u"", -1) ] # reset the event loop util.chatter = False self.saw_error = False self.error_signal_okay = False signals.system.connect('error', self.handle_error) app.controller = DummyController() self.httpserver = None httpauth.init() # reset any logging records from our setUp call() self.log_filter.reset_records() # create an extension manager that searches our tempdir for extensions # NOTE: this doesn't actually load any extensions, since the directory # is currently empty. If you want to use the ExtensionManager you # need to put a .miroext file in the tempdir then call # app.extension_manager.load_extension() app.extension_manager = extensionmanager.ExtensionManager( [self.tempdir], []) # Create a download state object (but don't start the downloader # for the individual test unless necessary. In this case we override # the class to run the downloader). app.download_state_manager = downloader.DownloadStateManager() self.mock_patchers = []
def test_invalid_device(self): self.build_config_file( "foo.py", """from miro.devices import DeviceInfo target1 = DeviceInfo("Target1") devices = [target1] """) dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, "*.py")) self.assertRaises(KeyError, dm.get_device, "Target1") self.assertRaises(KeyError, dm.get_device_by_id, 0, 0)
def on_frontend_started(): """Perform startup actions that should happen after the frontend is already up and running. This function happens using an idle iterator. Before/after code that could take a while to run, we yield to other eventloop callbacks. """ conversions.conversion_manager.startup() app.sharing_tracker = sharing.SharingTracker() app.sharing_manager.startup() app.sharing_tracker.start_tracking() app.device_manager = devices.DeviceManager() app.device_tracker = devicetracker.DeviceTracker() app.device_tracker.start_tracking() reconnect_downloaders() guide.download_guides() feed.remove_orphaned_feed_impls() app.download_state_manager.init_controller() itemsource.setup_handlers() if app.frontend_name == 'widgets': app.donate_manager = donate.DonateManager() else: logging.warn("frontend is %s, not starting DonateManager()", app.frontend_name) logging.info("Starting auto downloader...") autodler.start_downloader() app.icon_cache_updater.start_updates() yield None feed.expire_items() yield None commandline.startup() yield None autoupdate.check_for_updates() yield None app.local_metadata_manager.schedule_retry_net_lookup() # Delay running high CPU/IO operations for a bit eventloop.add_timeout(5, app.download_state_manager.startup_downloader, "start downloader daemon") eventloop.add_timeout(10, workerprocess.startup, "start worker process") eventloop.add_timeout(20, item.start_deleted_checker, "start checking deleted items") eventloop.add_timeout(30, feed.start_updates, "start feed updates") eventloop.add_timeout(60, item.update_incomplete_metadata, "update metadata data") eventloop.add_timeout(90, clear_icon_cache_orphans, "clear orphans")
def test_generic_device(self): self.build_config_file( "foo.py", """from miro.devices import DeviceInfo target1 = DeviceInfo("Target1", device_name='Foo*', vendor_id=0x1234, product_id=None, video_conversion="hero", audio_conversion="mp3", audio_types=".mp3 .aac".split(), mount_instructions=u"", video_path=u"Video", audio_path=u"Audio") devices = [target1] """) dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, '*.py')) device = dm.get_device('Foo Bar') self.assertEqual(device.name, "Target1") device = dm.get_device_by_id(0x1234, 0x4567) self.assertEqual(device.name, "Target1")
databaselog.print_old_log_entries() models.initialize() if DEBUG_DB_MEM_USAGE: util.db_mem_usage_test() mem_usage_test_event.set() # MetadataProgressUpdater needs to be installed before ItemInfoCache, # since ItemInfoCache may create items if it uses failsafe mode app.metadata_progress_updater = metadataprogress.MetadataProgressUpdater() app.item_info_cache = iteminfocache.ItemInfoCache() app.item_info_cache.load() dbupgradeprogress.upgrade_end() logging.info("Loading video converters...") conversions.conversion_manager.startup() app.device_manager = devices.DeviceManager() app.device_tracker = devicetracker.DeviceTracker() searchengines.create_engines() setup_global_feeds() # call fix_database_inconsistencies() ASAP after the manual feed is set up fix_database_inconsistencies() logging.info("setup tabs...") setup_tabs() logging.info("setup theme...") setup_theme() install_message_handler() itemsource.setup_handlers() downloader.init_controller() # Call this late, after the message handlers have been installed.
def test_parsing(self): self.build_config_file( "foo.py", """from miro.gtcache import gettext as _ from miro.devices import DeviceInfo, MultipleDeviceInfo defaults = { "audio_conversion": "mp3", "container_types": "isom mp3".split(), "audio_types": "mp3 aac".split(), "video_types": ["h264"], "mount_instructions": _("Mount Instructions\\nOver multiple lines"), "video_path": u"Video", "audio_path": u"Audio", } target1 = DeviceInfo("Target1", vendor_id=0x890a, product_id=0xbcde, device_name="Bar", video_conversion="mp4", **defaults) target2 = DeviceInfo('Target2', video_conversion="mp4") target3 = DeviceInfo('Target3', video_conversion="mp4") multiple = MultipleDeviceInfo('Foo', [target2, target3], vendor_id=0x1234, product_id=0x4567, **defaults) devices = [target1, multiple] """) dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, "*.py")) # a single device device = dm.get_device("Bar") self.assertEqual(repr(device), "<DeviceInfo 'Target1' 'Bar' 890a bcde>") # this comes from the section name self.assertEqual(device.name, "Target1") # this comes from the default self.assertEqual(device.audio_conversion, "mp3") # this comes from the section self.assertEqual(device.device_name, 'Bar') self.assertEqual(device.video_conversion, "mp4") self.assertEqual(device.audio_path, 'Audio') self.assertTrue(isinstance(device.audio_path, PlatformFilenameType)) self.assertEqual(device.video_path, 'Video') self.assertTrue(isinstance(device.video_path, PlatformFilenameType)) # these are a special case self.assertFalse(device.has_multiple_devices) self.assertEqual(device.mount_instructions, _('Mount Instructions\nOver multiple lines')) self.assertEqual(device.container_types, ['mp3', 'isom']) self.assertEqual(device.audio_types, ['mp3', 'aac']) self.assertEqual(device.video_types, ['h264']) # both devices have the same ID device = dm.get_device_by_id(0x1234, 0x4567) self.assertTrue(device.has_multiple_devices) self.assertEquals(device.name, 'Foo') self.assertEquals(device.device_name, 'Foo') self.assertEquals(device.vendor_id, 0x1234) self.assertEquals(device.product_id, 0x4567) self.assertEqual(device.mount_instructions, _('Mount Instructions\nOver multiple lines')) single = device.get_device('Target2') self.assertFalse(single.has_multiple_devices) self.assertEqual(single.name, 'Target2')
def test_empty(self): dm = devices.DeviceManager() dm.load_devices(os.path.join(self.tempdir, "*.py")) self.assertRaises(KeyError, dm.get_device, "py") self.assertRaises(KeyError, dm.get_device_by_id, 0, 0)