Beispiel #1
0
    def test_download_spotify(self):
        tests.clear_tmp_folder()

        dldr = downloader.Downloader()
        path = os.path.join(tests.DIR_TMP, 'spotify.apk')
        dldr.download_spotify(path)
        self.assertGreater(os.path.getsize(path), 20000000)
Beispiel #2
0
    def test_do_replacement(self):
        tests.clear_tmp_folder()

        shutil.copyfile(os.path.join(tests.DIR_LANG, 'file1_withgender.xml'),
                        os.path.join(tests.DIR_TMP, 'file1_withgender.xml'))
        shutil.copyfile(os.path.join(tests.DIR_LANG, 'file2_withgender.xml'),
                        os.path.join(tests.DIR_TMP, 'file2_withgender.xml'))

        path1 = os.path.join(tests.DIR_REPLACE, 'replacements_testadd.json')
        path2 = os.path.join(tests.DIR_REPLACE, 'replacements_part2.json')

        rt1 = replacement_table.ReplacementTable.from_file(path1)
        rt2 = replacement_table.ReplacementTable.from_file(path2)

        rpm = replacement_table.ReplacementManager(tests.DIR_TMP)
        rpm.add_rtab(rt1, 'rt1')
        rpm.add_rtab(rt2, 'rt2')

        rpm.do_replace()

        tests.assert_files_equal(
            self, os.path.join(tests.DIR_LANG, 'file1_nogender.xml'),
            os.path.join(tests.DIR_TMP, 'file1_withgender.xml'))
        tests.assert_files_equal(
            self, os.path.join(tests.DIR_LANG, 'file2_nogender.xml'),
            os.path.join(tests.DIR_TMP, 'file2_withgender.xml'))
Beispiel #3
0
    def _test_to_file(self, file):
        tests.clear_tmp_folder()
        path = os.path.join(tests.DIR_LANG, file)
        path_out = os.path.join(tests.DIR_TMP, 'lang.xml')

        lfile = lang_file.LangFile(path)
        lfile.to_file(path_out)

        tests.assert_files_equal(self, path, path_out)
Beispiel #4
0
    def test_workdir_creation(self):
        tests.clear_tmp_folder()
        workdir.Workdir(tests.DIR_TMP)
        dir_root = os.path.join(tests.DIR_TMP, 'GenderEx')

        self.assertTrue(
            os.path.isfile(os.path.join(dir_root, 'genderex.keystore')))
        self.assertTrue(os.path.isdir(os.path.join(dir_root, 'tmp')))
        self.assertTrue(os.path.isdir(os.path.join(dir_root, 'output')))
Beispiel #5
0
    def test_add_to_file(self):
        tests.clear_tmp_folder()

        path = os.path.join(tests.DIR_REPLACE, 'replacements_empty.json')
        path_out = os.path.join(tests.DIR_TMP, 'replacements.json')
        path_ass = os.path.join(tests.DIR_REPLACE, 'replacements_testadd.json')

        rt = replacement_table.ReplacementTable.from_file(path)

        rt.set_from_langfile('file1_withgender.xml').add(
            'Biblec', 'Künstler*innen', 'Künstler')

        rt.to_file(path_out)
        tests.assert_files_equal(self, path_ass, path_out)
Beispiel #6
0
    def _test_modify_file(self, file, file_mod, rkey):
        tests.clear_tmp_folder()
        path = os.path.join(tests.DIR_LANG, file)
        path_mod = os.path.join(tests.DIR_LANG, file_mod)
        path_out = os.path.join(tests.DIR_TMP, 'lang.xml')

        lfile = lang_file.LangFile(path)

        def fun_replace(key, old):
            if key == rkey:
                return 'MODIFIED'

        lfile.replace_tree(fun_replace)

        lfile.to_file(path_out)
        tests.assert_files_equal(self, path_mod, path_out)
Beispiel #7
0
    def test_write_replacement_table(self):
        tests.clear_tmp_folder()
        wd = workdir.Workdir(tests.DIR_TMP)
        dir_apk = wd._get_dir(wd.dir_apk)
        shutil.copyfile(os.path.join(tests.DIR_LANG, 'file1_withgender.xml'),
                        os.path.join(dir_apk, 'file1_withgender.xml'))
        shutil.copyfile(os.path.join(tests.DIR_LANG, 'file2_withgender.xml'),
                        os.path.join(dir_apk, 'file2_withgender.xml'))

        path = os.path.join(tests.DIR_TMP, 'replacements.json')
        shutil.copyfile(
            os.path.join(tests.DIR_REPLACE, 'replacements_testadd.json'), path)
        rt = replacement_table.ReplacementTable.from_file(path)

        rpm = replacement_table.ReplacementManager(
            dir_apk, lambda key, old: old + '_MOD')
        rpm.add_rtab(rt, 'rt', True)

        rpm.do_replace()
        rpm.write_replacement_table('newver')

        tests.assert_files_equal(
            self, os.path.join(tests.DIR_REPLACE,
                               'replacements_testwrite.json'), path)
Beispiel #8
0
    def _performance_test(self, folder):
        tests.clear_tmp_folder()

        DIR_INPUT = os.path.join(DIR_PERFORMANCE, folder)
        manager = replacement_table.ReplacementManager(DIR_INPUT)

        i = 1
        while True:
            file = os.path.join(DIR_INPUT, 'replacements_%d.json' % i)
            if os.path.isfile(file):
                rt = replacement_table.ReplacementTable.from_file(file)
                manager.add_rtab(rt, str(i))
            else:
                break
            i += 1

        start_time = time.time_ns()
        manager.do_replace(tests.DIR_TMP)

        runtime = time.time_ns() - start_time
        print('%s test took %d ms' % (folder, (runtime / 1000000)))

        tests.assert_files_equal(self, os.path.join(DIR_INPUT, 'lang_nogender.xml'),
                                 os.path.join(tests.DIR_TMP, 'lang.xml'))