当前位置: 首页>>代码示例>>Python>>正文


Python Project._should_download方法代码示例

本文整理汇总了Python中txclib.project.Project._should_download方法的典型用法代码示例。如果您正苦于以下问题:Python Project._should_download方法的具体用法?Python Project._should_download怎么用?Python Project._should_download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txclib.project.Project的用法示例。


在下文中一共展示了Project._should_download方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestProjectPull

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import _should_download [as 别名]

#.........这里部分代码省略.........
            mock.return_value = False
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', 'el-gr', ]))
            self.assertFalse(new)

            del self.files['el-gr']
            mock.return_value = True
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', ]))
            self.assertEqual(new, set(['el', ]))

            mock.return_value = False
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', ]))
            self.assertEqual(new, set([]))

    def test_in_combination_with_force_option(self):
        """Test the minimum-perc option along with -f."""
        with patch.object(self.p, 'get_resource_option') as mock:
            mock.return_value = 70

            res = self.p._should_download('de', self.stats, None, False)
            self.assertEqual(res, False)
            res = self.p._should_download('el', self.stats, None, False)
            self.assertEqual(res, False)
            res = self.p._should_download('el', self.stats, None, True)
            self.assertEqual(res, False)
            res = self.p._should_download('en', self.stats, None, False)
            self.assertEqual(res, True)
            res = self.p._should_download('en', self.stats, None, True)
            self.assertEqual(res, True)

            with patch.object(self.p, '_remote_is_newer'):
                res = self.p._should_download('pt', self.stats, None, False)
                self.assertEqual(res, True)
                res = self.p._should_download('pt', self.stats, None, True)
                self.assertEqual(res, True)

    def test_get_url_by_pull_mode(self):
        self.assertEqual(
            'pull_sourceastranslation_file',
            self.p._get_url_by_pull_mode(mode='sourceastranslation')
        )
        self.assertEqual(
            DEFAULT_PULL_URL,
            self.p._get_url_by_pull_mode(mode='invalid mode')
        )
        self.assertEqual(
            DEFAULT_PULL_URL,
            self.p._get_url_by_pull_mode(mode=None)
        )

    def fixture_mocked_project(func):
        """A mock object with main os and http operations mocked"""
开发者ID:transifex,项目名称:transifex-client,代码行数:70,代码来源:test_project.py

示例2: TestProjectPull

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import _should_download [as 别名]

#.........这里部分代码省略.........
        pseudo_file = self.p._get_pseudo_file(slang, resource, file_filter)

        self.assertEqual(pseudo_file, 'adriana/en_pseudo.po')

    def test_languages_to_pull_empty_initial_list(self):
        """Test determining the languages to pull, when the initial
        list is empty.
        """
        languages = []
        force = False

        res = self.p._languages_to_pull(
            languages, self.files, self.lang_map, self.stats, force
        )
        existing = res[0]
        new = res[1]
        self.assertEqual(existing, set(['el', 'en', 'pt']))
        self.assertFalse(new)

        del self.files['el']
        self.files['el-gr'] = None
        self.lang_map['el'] = 'el-gr'
        res = self.p._languages_to_pull(
            languages, self.files, self.lang_map, self.stats, force
        )
        existing = res[0]
        new = res[1]
        self.assertEqual(existing, set(['el', 'en', 'pt']))
        self.assertFalse(new)

    def test_languages_to_pull_with_initial_list(self):
        """Test determining the languages to pull, then there is a
        language selection from the user.
        """
        languages = ['el', 'en']
        self.lang_map['el'] = 'el-gr'
        del self.files['el']
        self.files['el-gr'] = None
        force = False

        with patch.object(self.p, '_should_add_translation') as mock:
            mock.return_value = True
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', 'el-gr', ]))
            self.assertFalse(new)

            mock.return_value = False
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', 'el-gr', ]))
            self.assertFalse(new)

            del self.files['el-gr']
            mock.return_value = True
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', ]))
            self.assertEqual(new, set(['el', ]))

            mock.return_value = False
            res = self.p._languages_to_pull(
                languages, self.files, self.lang_map, self.stats, force
            )
            existing = res[0]
            new = res[1]
            self.assertEqual(existing, set(['en', ]))
            self.assertEqual(new, set([]))

    def test_in_combination_with_force_option(self):
        """Test the minumum-perc option along with -f."""
        with patch.object(self.p, 'get_resource_option') as mock:
            mock.return_value = 70

            res = self.p._should_download('de', self.stats, None, False)
            self.assertEqual(res, False)
            res = self.p._should_download('el', self.stats, None, False)
            self.assertEqual(res, False)
            res = self.p._should_download('el', self.stats, None, True)
            self.assertEqual(res, False)
            res = self.p._should_download('en', self.stats, None, False)
            self.assertEqual(res, True)
            res = self.p._should_download('en', self.stats, None, True)
            self.assertEqual(res, True)

            with patch.object(self.p, '_remote_is_newer') as local_file_mock:
                local_file_mock = False
                res = self.p._should_download('pt', self.stats, None, False)
                self.assertEqual(res, True)
                res = self.p._should_download('pt', self.stats, None, True)
                self.assertEqual(res, True)
开发者ID:TASERAxon,项目名称:transifex-client,代码行数:104,代码来源:test_project.py

示例3: TestProjectPull

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import _should_download [as 别名]

#.........这里部分代码省略.........
            with patch.object(self.p, "_should_add_translation") as filter_mock:
                filter_mock.return_value = True
                for force in [True, False]:
                    res = new_trans({"el": None}, self.slang, self.lang_map, self.stats, force)
                    self.assertEquals(res, set(["pt"]))
                for force in [True, False]:
                    res = new_trans({}, self.slang, self.lang_map, self.stats, force)
                    self.assertEquals(res, set(["el", "pt"]))

                files = {}
                files["pt_PT"] = None
                lang_map = {"pt": "pt_PT"}
                for force in [True, False]:
                    res = new_trans(files, self.slang, lang_map, self.stats, force)
                    self.assertEquals(res, set(["el"]))

    def test_languages_to_pull_empty_initial_list(self):
        """Test determining the languages to pull, when the initial
        list is empty.
        """
        languages = []
        force = False

        res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
        existing = res[0]
        new = res[1]
        self.assertEquals(existing, set(["el", "en", "pt"]))
        self.assertFalse(new)

        del self.files["el"]
        self.files["el-gr"] = None
        self.lang_map["el"] = "el-gr"
        res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
        existing = res[0]
        new = res[1]
        self.assertEquals(existing, set(["el", "en", "pt"]))
        self.assertFalse(new)

    def test_languages_to_pull_with_initial_list(self):
        """Test determining the languages to pull, then there is a
        language selection from the user.
        """
        languages = ["el", "en"]
        self.lang_map["el"] = "el-gr"
        del self.files["el"]
        self.files["el-gr"] = None
        force = False

        with patch.object(self.p, "_should_add_translation") as mock:
            mock.return_value = True
            res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
            existing = res[0]
            new = res[1]
            self.assertEquals(existing, set(["en", "el-gr"]))
            self.assertFalse(new)

            mock.return_value = False
            res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
            existing = res[0]
            new = res[1]
            self.assertEquals(existing, set(["en", "el-gr"]))
            self.assertFalse(new)

            del self.files["el-gr"]
            mock.return_value = True
            res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
            existing = res[0]
            new = res[1]
            self.assertEquals(existing, set(["en"]))
            self.assertEquals(new, set(["el"]))

            mock.return_value = False
            res = self.p._languages_to_pull(languages, self.files, self.lang_map, self.stats, force)
            existing = res[0]
            new = res[1]
            self.assertEquals(existing, set(["en"]))
            self.assertEquals(new, set([]))

    def test_in_combination_with_force_option(self):
        """Test the minumum-perc option along with -f."""
        with patch.object(self.p, "get_resource_option") as mock:
            mock.return_value = 70

            res = self.p._should_download("de", self.stats, None, False)
            self.assertEquals(res, False)
            res = self.p._should_download("el", self.stats, None, False)
            self.assertEquals(res, False)
            res = self.p._should_download("el", self.stats, None, True)
            self.assertEquals(res, False)
            res = self.p._should_download("en", self.stats, None, False)
            self.assertEquals(res, True)
            res = self.p._should_download("en", self.stats, None, True)
            self.assertEquals(res, True)

            with patch.object(self.p, "_remote_is_newer") as local_file_mock:
                local_file_mock = False
                res = self.p._should_download("pt", self.stats, None, False)
                self.assertEquals(res, True)
                res = self.p._should_download("pt", self.stats, None, True)
                self.assertEquals(res, True)
开发者ID:keiji,项目名称:android,代码行数:104,代码来源:test_project.py


注:本文中的txclib.project.Project._should_download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。