def test_scraping_assets_for_game(self, cache_mock, search_cache_mock):

        # arrange
        settings = self.get_test_settings()
        
        assets_to_scrape = [
            g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID), 
            g_assetFactory.get_asset_info(ASSET_BOXBACK_ID), 
            g_assetFactory.get_asset_info(ASSET_SNAP_ID)]
        
        launcher = StandardRomLauncher(None, settings, None, None, None, None, None)
        launcher.set_platform('Nintendo SNES')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID),'/my/nice/assets/front/')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_BOXBACK_ID),'/my/nice/assets/back/')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_SNAP_ID),'/my/nice/assets/snaps/')
        
        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/castlevania.zip')
        
        target = LocalAssetScraper(settings, launcher)

        # act
        actuals = []
        for asset_to_scrape in assets_to_scrape:
            an_actual = target.scrape_asset('castlevania', asset_to_scrape, fakeRomPath, rom)
            actuals.append(an_actual)
                
        # assert
        for actual in actuals:
            self.assertFalse(actual)
        
        print(rom)
Example #2
0
    def test_scraping_assets_for_game(self, mock_img_downloader, mock_json_downloader):

        # arrange
        settings = self.get_test_settings()
        
        assets_to_scrape = [
            g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID), 
            g_assetFactory.get_asset_info(ASSET_BOXBACK_ID), 
            g_assetFactory.get_asset_info(ASSET_SNAP_ID)]
        
        launcher = StandardRomLauncher(None, settings, None, None, None, None, None)
        launcher.set_platform('MAME')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID),'/my/nice/assets/front/')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_BOXBACK_ID),'/my/nice/assets/back/')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_SNAP_ID),'/my/nice/assets/snaps/')
        
        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/dino.zip')

        target = ArcadeDbScraper(settings, launcher)

        # act
        actuals = []
        for asset_to_scrape in assets_to_scrape:
            an_actual = target.scrape_asset('dino', asset_to_scrape, fakeRomPath, rom)
            actuals.append(an_actual)
                
        # assert
        for actual in actuals:
            self.assertTrue(actual)
        
        print(rom)
Example #3
0
    def test_scraping_metadata_for_game(self):

        # arrange
        settings = self.get_test_settings()

        launcher = StandardRomLauncher(None, settings, None, None, None, None,
                                       None)
        launcher.set_platform('Nintendo SNES')

        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile(Test_nfo_scraper.TEST_ASSETS_DIR +
                               '\\dr_mario.zip')
        with open(Test_nfo_scraper.TEST_ASSETS_DIR + "\\dr_mario.nfo",
                  'r') as f:
            fakeRomPath.setFakeContent(f.read())

        target = NfoScraper(settings, launcher)

        # act
        actual = target.scrape_metadata('doctor mario', fakeRomPath, rom)

        # assert
        self.assertTrue(actual)
        self.assertEqual(u'Dr. Mario', rom.get_name())
        self.assertEqual(u'Puzzle', rom.get_genre())
        print(rom)
Example #4
0
    def test_if_retroarch_launcher_will_apply_the_correct_arguments_when_running_on_android(
            self, mock_exeFactory, is_linux_mock, is_android_mock, is_win_mock,
            mock_file):

        # arrange
        is_linux_mock.return_value = False
        is_win_mock.return_value = False
        is_android_mock.return_value = True

        settings = self._get_test_settings()

        launcher_data = {}
        launcher_data['type'] = OBJ_LAUNCHER_RETROARCH
        launcher_data['id'] = 'ABC'
        launcher_data['toggle_window'] = True
        launcher_data['romext'] = None
        launcher_data['args_extra'] = None
        launcher_data['roms_base_noext'] = 'snes'
        launcher_data[
            'retro_core'] = '/data/data/com.retroarch/cores/mame_libretro_android.so'
        launcher_data[
            'retro_config'] = '/storage/emulated/0/Android/data/com.retroarch/files/retroarch.cfg'
        launcher_data['application'] = None

        rom_id = 'qqqq'
        rom = {}
        rom['id'] = 'qqqq'
        rom['m_name'] = 'TestCase'
        rom['filename'] = 'superrom.zip'
        rom['altapp'] = None
        roms = {rom_id: rom}
        json_data = json.dumps(roms,
                               ensure_ascii=False,
                               indent=1,
                               separators=(',', ':'))

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        rom_dir.setFakeContent(json_data)

        mock = FakeExecutor()
        mock_exeFactory.create.return_value = mock
        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = rom_dir

        repository = ROMSetRepository(paths, settings)
        launcher = RetroarchLauncher(paths, settings, launcher_data, None,
                                     mock_exeFactory, repository, None)
        launcher.select_ROM(rom_id)

        expected = '/system/bin/am'
        expectedArgs = "start --user 0 -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n com.retroarch/.browser.retroactivity.RetroActivityFuture -e ROM 'superrom.zip' -e LIBRETRO /data/data/com.retroarch/cores/mame_libretro_android.so -e CONFIGFILE /storage/emulated/0/Android/data/com.retroarch/files/retroarch.cfg "

        # act
        launcher.launch()

        # assert
        self.assertEqual(expected, mock.getActualApplication().getPath())
        self.assertEqual(expectedArgs, mock.actualArgs)
    def test_when_finding_launchers_by_category_it_will_give_the_correct_result(
            self):

        # arrange
        xml_path = FakeFile(self.TEST_ASSETS_DIR + "\\ms_categories.xml")
        context = XmlDataContext(xml_path)
        factory = LauncherFactory({}, None, FakeFile(self.TEST_ASSETS_DIR))
        target = LauncherRepository(context, factory)

        expected = 5
        cat_id = 'c20f56e7c2242b03e8133c512303ec63'

        # act
        actual = target.find_by_category(cat_id)

        # assert
        self.assertIsNotNone(actual)
        self.assertEqual(len(actual), expected)
Example #6
0
    def test_if_rom_launcher_will_apply_the_correct_disc_in_a_multidisc_situation(
            self, mock_exeFactory, mock_dialog, mock_file):

        # arrange
        settings = self._get_test_settings()

        launcher_data = {}
        launcher_data['id'] = 'ABC'
        launcher_data['type'] = OBJ_LAUNCHER_ROM
        launcher_data['application'] = 'c:\\temp\\'
        launcher_data['toggle_window'] = True
        launcher_data['romext'] = ''
        launcher_data['application'] = ''
        launcher_data['args'] = '-a -b -c -d -e $rom$ -yes'
        launcher_data['args_extra'] = ''
        launcher_data['roms_base_noext'] = 'snes'

        rom = {}
        rom['id'] = 'qqqq'
        rom['m_name'] = 'TestCase'
        rom['filename'] = 'd:\\games\\discXX.zip'
        rom['altapp'] = ''
        rom['altarg'] = ''
        rom['disks'] = ['disc01.zip', 'disc02.zip']

        rom_id = rom['id']
        roms = {rom_id: rom}
        json_data = json.dumps(roms,
                               ensure_ascii=False,
                               indent=1,
                               separators=(',', ':'))

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        rom_dir.setFakeContent(json_data)

        mock_dialog.return_value = 1
        mock = FakeExecutor()
        mock_exeFactory.create.return_value = mock

        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = rom_dir

        repository = ROMSetRepository(paths, settings)
        launcher = StandardRomLauncher(paths, settings, launcher_data, None,
                                       mock_exeFactory, repository, None)
        launcher.select_ROM(rom_id)

        expected = launcher_data['application']
        expectedArgs = '-a -b -c -d -e d:\\games\\disc02.zip -yes'

        # act
        launcher.launch()

        # assert
        self.assertEqual(expectedArgs, mock.actualArgs)
Example #7
0
    def test_if_rom_launcher_will_correctly_passthrough_the_application_when_launching(
            self, mock_exeFactory, mock_file):

        # arrange
        settings = self._get_test_settings()

        launcher_data = {}
        launcher_data['id'] = 'ABC'
        launcher_data['type'] = OBJ_LAUNCHER_ROM
        launcher_data['application'] = 'path'
        launcher_data['toggle_window'] = True
        launcher_data['romext'] = ''
        launcher_data['application'] = ''
        launcher_data['args'] = '-a -b -c -d -e $rom$ -yes'
        launcher_data['args_extra'] = ''
        launcher_data['roms_base_noext'] = 'snes'

        rom_id = 'fghj'
        rom = {
            'id': rom_id,
            'm_name': 'TestCase',
            'filename': 'testing.zip',
            'altapp': '',
            'altarg': ''
        }
        roms = {rom_id: rom}
        json_data = json.dumps(roms,
                               ensure_ascii=False,
                               indent=1,
                               separators=(',', ':'))

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        rom_dir.setFakeContent(json_data)

        mock = FakeExecutor()
        mock_exeFactory.create.return_value = mock

        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = rom_dir

        repository = ROMSetRepository(paths, settings)
        launcher = StandardRomLauncher(paths, settings, launcher_data, None,
                                       mock_exeFactory, repository, None)
        launcher.select_ROM(rom_id)

        expected = launcher_data['application']
        expectedArgs = '-a -b -c -d -e testing.zip -yes'

        # act
        launcher.launch()

        # assert
        self.assertIsNotNone(mock.actualApplication)
        self.assertEqual(expected, mock.actualApplication.getPath())
        self.assertEqual(expectedArgs, mock.actualArgs)
Example #8
0
    def test_if_rom_launcher_will_use_the_multidisk_launcher_when_romdata_has_disks_field_filled_in(
            self, mock_exeFactory, mock_file):

        # arrange
        settings = self._get_test_settings()

        launcher_data = {}
        launcher_data['id'] = 'ABC'
        launcher_data['type'] = OBJ_LAUNCHER_ROM
        launcher_data['application'] = 'path'
        launcher_data['toggle_window'] = True
        launcher_data['romext'] = ''
        launcher_data['application'] = ''
        launcher_data['args'] = ''
        launcher_data['args_extra'] = ''
        launcher_data['roms_base_noext'] = 'snes'

        rom_id = 'fghj'
        rom = {
            'id': rom_id,
            'm_name': 'TestCase',
            'disks': ['disc01.zip', 'disc02.zip']
        }
        roms = {rom_id: rom}
        json_data = json.dumps(roms,
                               ensure_ascii=False,
                               indent=1,
                               separators=(',', ':'))

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        rom_dir.setFakeContent(json_data)

        mock = FakeExecutor()
        mock_exeFactory.create.return_value = mock

        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = rom_dir

        repository = ROMSetRepository(paths, settings)
        launcher = StandardRomLauncher(paths, settings, launcher_data, None,
                                       mock_exeFactory, repository, None)

        # act
        launcher.select_ROM(rom_id)

        # assert
        actual = launcher.__class__.__name__
        expected = 'StandardRomLauncher'
        self.assertEqual(actual, expected)
    def test_when_finding_categories_it_will_give_the_correct_result(self):

        # arrange
        xml_path = FakeFile(self.TEST_ASSETS_DIR + "\\ms_categories.xml")
        context = XmlDataContext(xml_path)
        target = CategoryRepository(context)

        expected = 7

        # act
        actual = target.find_all()

        # assert
        self.assertIsNotNone(actual)
        self.assertEqual(len(actual), expected)
    def test_scraping_metadata_for_game(self):
        
        # arrange
        settings = self.get_test_settings()
        
        launcher = StandardRomLauncher(None, settings, None, None, None, None, None)
        launcher.set_platform('Nintendo SNES')
        
        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/dr_mario.zip')

        target = LocalAssetScraper(settings, launcher)

        # act
        actual = target.scrape_metadata('doctor mario', fakeRomPath, rom)
                
        # assert
        self.assertFalse(actual)
        print(rom)
Example #11
0
    def test_scraping_metadata_for_game(self, mock_json_downloader):
        
        # arrange
        settings = self.get_test_settings()

        launcher = StandardRomLauncher(None, settings, None, None, None, None, None)
        launcher.set_platform('MAME')
        
        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/dino.zip')

        target = ArcadeDbScraper(settings, launcher)

        # act
        actual = target.scrape_metadata('dino', fakeRomPath, rom)
                
        # assert
        self.assertTrue(actual)
        self.assertEqual(u'Cadillacs and Dinosaurs (World 930201)', rom.get_name())
        print(rom)
Example #12
0
    def test_when_using_rom_the_factory_will_get_the_correct_launcher(
            self, mock_exeFactory):

        # arrange
        settings = self._get_test_settings()

        launcher_data = {}
        launcher_data['id'] = 'ABC'
        launcher_data['application'] = 'path'
        launcher_data['type'] = OBJ_LAUNCHER_ROM
        launcher_data['toggle_window'] = True
        launcher_data['romext'] = ''
        launcher_data['application'] = ''
        launcher_data['args'] = ''
        launcher_data['args_extra'] = ''
        launcher_data['roms_base_noext'] = 'snes'

        rom_id = 'fghj'
        rom = {'id': rom_id, 'm_name': 'TestCase'}
        roms = {rom_id: rom}
        json_data = json.dumps(roms,
                               ensure_ascii=False,
                               indent=1,
                               separators=(',', ':'))

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        rom_dir.setFakeContent(json_data)

        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = NewFileName(self.TEST_ASSETS_DIR)
        repository = ROMSetRepository(paths, settings)

        # act
        launcher = StandardRomLauncher(paths, settings, launcher_data, None,
                                       mock_exeFactory, repository, None)
        launcher.select_ROM(rom_id)

        # assert
        actual = launcher.__class__.__name__
        expected = 'StandardRomLauncher'
        self.assertEqual(actual, expected)
    def test_scraping_metadata_for_game(self, mock_htmlpost_downloader,
                                        mock_html_downloader):

        # arrange
        settings = self.get_test_settings()

        launcher = StandardRomLauncher(None, settings, None, None, None, None,
                                       None)
        launcher.set_platform('Nintendo NES')

        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/castlevania.zip')

        target = GameFaqScraper(settings, launcher)

        # act
        actual = target.scrape_metadata('castlevania', fakeRomPath, rom)

        # assert
        self.assertTrue(actual)
        self.assertEqual(u'Castlevania', rom.get_name())
        print(rom)
    def test_scraping_assets_for_game(self, mock_img_downloader,
                                      mock_htmlpost_downloader,
                                      mock_html_downloader):

        # arrange
        settings = self.get_test_settings()

        assets_to_scrape = [
            g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID),
            g_assetFactory.get_asset_info(ASSET_SNAP_ID)
        ]

        launcher = StandardRomLauncher(None, settings, None, None, None, None,
                                       None)
        launcher.set_platform('Nintendo NES')
        launcher.set_asset_path(
            g_assetFactory.get_asset_info(ASSET_BOXFRONT_ID),
            '/my/nice/assets/fronts/')
        launcher.set_asset_path(g_assetFactory.get_asset_info(ASSET_SNAP_ID),
                                '/my/nice/assets/snaps/')

        rom = ROM({'id': 1234})
        fakeRomPath = FakeFile('/my/nice/roms/castlevania.zip')

        target = GameFaqScraper(settings, launcher)

        # act
        actuals = []
        for asset_to_scrape in assets_to_scrape:
            an_actual = target.scrape_asset('castlevania', asset_to_scrape,
                                            fakeRomPath, rom)
            actuals.append(an_actual)

        # assert
        for actual in actuals:
            self.assertTrue(actual)

        print(rom)
    def test_storing_roms_will_create_a_file_with_correct_contents(self):

        # arrange
        settings = self._get_test_settings()

        rom_dir = FakeFile(self.TEST_ASSETS_DIR)
        paths = Fake_Paths('\\fake\\')
        paths.ROMS_DIR = rom_dir

        target = ROMSetRepository(paths, settings)
        launcher_data = {'id': 'abc', 'roms_base_noext': 'testcase'}
        launcher = StandardRomLauncher(paths, settings, launcher_data, None,
                                       None, target, None)

        roms = {}
        roms['1234'] = ROM()
        roms['9998'] = ROM()
        roms['7845'] = ROM()

        # act
        target.save_rom_set(launcher, roms)

        # assert
        print(rom_dir.getFakeContent())