本文整理汇总了Python中txclib.project.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_specifying_resources
def test_specifying_resources(self):
"""Test the various ways to specify resources in a project."""
p = Project(init=False)
resources = [
'proj1.res1',
'proj2.res2',
'transifex.txn',
'transifex.txo',
]
with patch.object(p, 'get_resource_list') as mock:
mock.return_value = resources
cmd_args = [
'proj1.res1', '*1*', 'transifex*', '*r*',
'*o', 'transifex.tx?', 'transifex.txn',
]
results = [
['proj1.res1', ],
['proj1.res1', ],
['transifex.txn', 'transifex.txo', ],
['proj1.res1', 'proj2.res2', 'transifex.txn', 'transifex.txo', ], # noqa
['transifex.txo', ],
['transifex.txn', 'transifex.txo', ],
['transifex.txn', ],
[],
]
for i, arg in enumerate(cmd_args):
resources = [arg]
self.assertEqual(p.get_chosen_resources(resources), results[i])
# wrong argument
resources = ['*trasnifex*', ]
self.assertRaises(Exception, p.get_chosen_resources, resources)
示例2: test_specifying_resources
def test_specifying_resources(self):
"""Test the various ways to specify resources in a project."""
p = Project(init=False)
resources = ["proj1.res1", "proj2.res2", "transifex.txn", "transifex.txo"]
with patch.object(p, "get_resource_list") as mock:
mock.return_value = resources
cmd_args = ["proj1.res1", "*1*", "transifex*", "*r*", "*o", "transifex.tx?", "transifex.txn"]
results = [
["proj1.res1"],
["proj1.res1"],
["transifex.txn", "transifex.txo"],
["proj1.res1", "proj2.res2", "transifex.txn", "transifex.txo"],
["transifex.txo"],
["transifex.txn", "transifex.txo"],
["transifex.txn"],
[],
]
for i, arg in enumerate(cmd_args):
resources = [arg]
self.assertEqual(p.get_chosen_resources(resources), results[i])
# wrong argument
resources = ["*trasnifex*"]
self.assertRaises(Exception, p.get_chosen_resources, resources)
示例3: __init__
def __init__(self, path_to_tx):
p = Project(path_to_tx)
self.host = p.config.get('main', 'host')
username, token_or_password = p.getset_host_credentials(
self.host, only_token=True)
self.api = Api(username=username, password=token_or_password,
host=self.host, path_to_tx=p.txrc_file)
示例4: test_extract_fields
def test_extract_fields(self):
"""Test the functions that extract a field from a stats object."""
stats = {
'completed': '80%',
'last_update': '00:00',
'foo': 'bar',
}
self.assertEqual(
stats['completed'], '%s%%' % Project._extract_completed(stats)
)
self.assertEqual(stats['last_update'], Project._extract_updated(stats))
示例5: test_getset_host_credentials_env_variable_first_time
def test_getset_host_credentials_env_variable_first_time(
self, m_parser, m_input):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
# ensure that we have set host in the txrc_file, even though TX_TOKEN
# exists
self.assertEqual(p.txrc.set.call_count, 2)
p.save.assert_called()
示例6: test_getset_host_credentials_env_variable
def test_getset_host_credentials_env_variable(
self, m_parser, m_input):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
self.assertEqual(p.txrc.set.call_count, 2)
# no input will be asked, password will be used by environment variable
self.assertEqual(m_input.call_count, 0)
p.save.assert_called()
示例7: test_getset_host_credentials_both_token_and_env
def test_getset_host_credentials_both_token_and_env(
self, m_logger, m_parser):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test', token='demo')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
# ensure that we did not make additional calls to set the token in the
# txrc file
self.assertEqual(p.txrc.set.call_count, 2)
p.save.assert_called()
self.assertEqual(m_logger.warning.call_count, 1)
示例8: main
def main():
l10nToolsDirectory = os.path.dirname(os.path.realpath(__file__))
projectRootDirectory = os.path.abspath(os.path.join(l10nToolsDirectory, os.pardir, os.pardir, os.pardir))
l10nFolderName = "l10n"
transifexClientFolder = ".tx"
for root, folders, filenames in os.walk(projectRootDirectory):
root = root.decode('utf-8')
for folder in folders:
if folder == l10nFolderName:
if os.path.exists(os.path.join(root, folder, transifexClientFolder)):
path = os.path.join(root, folder)
os.chdir(path)
project = Project(path)
project.pull(fetchall=True, force=True)
示例9: TestOptions
class TestOptions(unittest.TestCase):
"""Test the methods related to parsing the configuration file."""
def setUp(self):
self.p = Project(init=False)
def test_get_option(self):
"""Test _get_option method."""
with patch.object(self.p, 'get_resource_option') as rmock:
with patch.object(self.p, 'config', create=True) as cmock:
rmock.return_value = 'resource'
cmock.has_option.return_value = 'main'
cmock.get.return_value = 'main'
self.assertEqual(self.p._get_option(None, None), 'resource')
rmock.return_value = None
cmock.has_option.return_value = 'main'
cmock.get.return_value = 'main'
self.assertEqual(self.p._get_option(None, None), 'main')
cmock.has_option.return_value = None
self.assertIs(self.p._get_option(None, None), None)
示例10: setUp
def setUp(self):
super(TestProjectFilters, self).setUp()
self.p = Project(init=False)
self.p.minimum_perc = None
self.p.resource = "resource"
self.stats = {
"en": {"completed": "100%", "last_update": "2011-11-01 15:00:00"},
"el": {"completed": "60%", "last_update": "2011-11-01 15:00:00"},
"pt": {"completed": "70%", "last_update": "2011-11-01 15:00:00"},
}
self.langs = self.stats.keys()
示例11: TestOptions
class TestOptions(unittest.TestCase):
"""Test the methods related to parsing the configuration file."""
def setUp(self):
self.p = Project(init=False)
def test_get_option(self):
"""Test _get_option method."""
with contextlib.nested(
patch.object(self.p, "get_resource_option"), patch.object(self.p, "config", create=True)
) as (rmock, cmock):
rmock.return_value = "resource"
cmock.has_option.return_value = "main"
cmock.get.return_value = "main"
self.assertEqual(self.p._get_option(None, None), "resource")
rmock.return_value = None
cmock.has_option.return_value = "main"
cmock.get.return_value = "main"
self.assertEqual(self.p._get_option(None, None), "main")
cmock.has_option.return_value = None
self.assertIs(self.p._get_option(None, None), None)
示例12: wrapper
def wrapper(*args, **kwargs):
app_dir = dirname(modules['txclib'].__file__)
config_file = app_dir + "/../tests/templates/config"
transifex_file = app_dir + "/../tests/templates/transifexrc"
with patch("txclib.utils.encode_args") as mock_encode_args, \
patch("txclib.utils.determine_charset")\
as mock_determine_charset, \
patch("txclib.utils.get_transifex_file",
return_value=transifex_file) \
as mock_get_transifex_file, \
patch("txclib.utils.get_config_file_path",
return_value=config_file) \
as mock_get_config_file_path, \
patch("txclib.utils.save_txrc_file") \
as mock_save_txrc_file, \
patch("txclib.project.Project._get_stats_for_resource") \
as mock_get_stats_for_resource:
# Create fake https response
def encode_args(*args, **kwargs):
struct = namedtuple("response", "data status close")
return struct(status=401, data="mock_response",
close=Mock())
mock_determine_charset.return_value = "utf-8"
mock_encode_args.return_value = encode_args
# Mock configuration files
p = Project(init=False)
p._init(path_to_tx=app_dir + "/../templates")
kwargs['mock_project'] = p
kwargs['mocks'] = {
'mock_determine_charset': mock_determine_charset,
"mock_encode_args": mock_encode_args,
"mock_get_config_file_path": mock_get_config_file_path,
"mock_get_stats_for_resource": mock_get_stats_for_resource,
"mock_get_transifex_file": mock_get_transifex_file,
"mock_save_txrc_file": mock_save_txrc_file
}
return func(*args, **kwargs)
示例13: test_getset_host_credentials
def test_getset_host_credentials(self, m_parser):
p = Project(init=False)
# let suppose a token has been set at the config
dummy_token = 'salala'
p.txrc = m_parser
p.txrc.add_section = Mock()
p.txrc.set = Mock()
p.txrc.get = Mock()
p.txrc.get.side_effect = ['api', dummy_token, None, None]
p.txrc_file = '/tmp'
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
# let's try to get credentials for someone without
# a token
p.txrc.get.side_effect = [
'username',
'passw0rdz'
]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'username')
self.assertEqual(password, 'passw0rdz')
示例14: test_getset_host_credentials_update_transifexrc
def test_getset_host_credentials_update_transifexrc(
self, m_parser, m_input):
p = Project(init=False)
dummy_token = 'salala'
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.validate_credentials = Mock(return_value=True)
p.txrc.get.side_effect = [
'foo', 'bar'
]
# transifexrc does not get updated if credentials are the same
username, password = p.getset_host_credentials(
'test', username='foo', password='bar'
)
self.assertEqual(username, 'foo')
self.assertEqual(password, 'bar')
self.assertEqual(p.txrc.set.call_count, 0)
self.assertEqual(m_input.call_count, 0)
self.assertEqual(p.save.call_count, 0)
# transifexrc is not updated if confirm is no
p.txrc.get.side_effect = [
'foo', 'bar'
]
m_input.return_value = False
username, password = p.getset_host_credentials('test',
token=dummy_token)
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
self.assertEqual(p.txrc.set.call_count, 0)
self.assertEqual(m_input.call_count, 1)
self.assertEqual(p.save.call_count, 0)
# transifexrc is not updated if confirm is yes
p.txrc.get.side_effect = [
'foo', 'bar'
]
m_input.return_value = True
m_input.reset_mock()
username, password = p.getset_host_credentials('test',
token=dummy_token)
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
self.assertEqual(p.txrc.set.call_count, 2)
self.assertEqual(m_input.call_count, 1)
p.save.assert_called()
示例15: TestFormats
class TestFormats(unittest.TestCase):
"""Tests for the supported formats."""
def setUp(self):
self.p = Project(init=False)
def test_extensions(self):
"""Test returning the correct extension for a format."""
sample_formats = {"PO": {"file-extensions": ".po, .pot"}, "QT": {"file-extensions": ".ts"}}
extensions = [".po", ".ts", ""]
with patch.object(self.p, "do_url_request") as mock:
mock.return_value = json.dumps(sample_formats)
for (type_, ext) in zip(["PO", "QT", "NONE"], extensions):
extension = self.p._extension_for(type_)
self.assertEquals(extension, ext)