本文整理汇总了Python中unittest.main方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.main方法的具体用法?Python unittest.main怎么用?Python unittest.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.main方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCatchBreakInstallsHandler
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def testCatchBreakInstallsHandler(self):
module = sys.modules['unittest.main']
original = module.installHandler
def restore():
module.installHandler = original
self.addCleanup(restore)
self.installed = False
def fakeInstallHandler():
self.installed = True
module.installHandler = fakeInstallHandler
program = self.program
program.catchbreak = True
program.testRunner = FakeRunner
program.runTests()
self.assertTrue(self.installed)
示例2: test_get_log_for_test
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_get_log_for_test(self):
"""
Tests if we get the logs for test correctly
"""
test = testobj.Test("Testing_Logs",None,phase=0,iteration=0)
test.start_time = time.time()
time.sleep(2)
test.end_time = time.time()
runtime.set_active_tests([test])
output_path = '/tmp/test_test_utils_logs_output'
if not os.path.exists(output_path):
os.mkdir(output_path)
with open(os.path.join(output_path, 'test.log'), 'w') as f:
f.write('23:59:59 [main] INFO Testing_Logs')
with open(os.path.join(output_path, 'test.log'), 'w') as f:
f.write('23:59:59 [main] INFO TestClientService - Sent 100')
示例3: test_install_plugin_own_project_no_data
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_install_plugin_own_project_no_data(self):
""" Test installing a new plugin on a project for which you're the
main maintainer.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token aaabbbcccddd"}
# Install a plugin on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Mail/install", headers=headers
)
self.assertEqual(output.status_code, 400)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EINVALIDREQ.name, data["error_code"]
)
self.assertEqual(pagure.api.APIERROR.EINVALIDREQ.value, data["error"])
self.assertEqual(
data["errors"], {"mail_to": ["This field is required."]}
)
示例4: test_install_plugin_own_project
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_install_plugin_own_project(self):
""" Test installing a new plugin on a project for which you're the
main maintainer.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token aaabbbcccddd"}
# complete data set
data = {"mail_to": "serg@wh40k.com"}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Mail/install", headers=headers, data=data
)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
data,
{
"plugin": {"mail_to": "serg@wh40k.com"},
"message": "Hook 'Mail' activated",
},
)
示例5: test_install_plugin_someone_else_project_project_less_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_install_plugin_someone_else_project_project_less_token(self):
""" Test installing a new plugin on a project with which you have
nothing to do.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-less-foo"}
# Install a plugin on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Prevent creating new branches by git push/"
"install",
headers=headers,
)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
data,
{
"plugin": {},
"message": "Hook 'Prevent creating new branches by git push' "
"activated",
},
)
示例6: test_install_plugin_project_specific_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_install_plugin_project_specific_token(self):
""" Test installing a new plugin on a project with a regular
project-specific token.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-specific-foo"}
# complete data set
data = {"mail_to": "serg@wh40k.com"}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Mail/install", headers=headers, data=data
)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
data,
{
"plugin": {"mail_to": "serg@wh40k.com"},
"message": "Hook 'Mail' activated",
},
)
示例7: test_install_plugin_invalid_project_specific_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_install_plugin_invalid_project_specific_token(self):
""" Test installing a new plugin on a project with a regular
project-specific token but for another project.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-specific-foo"}
# complete data set
data = {"mail_to": "serg@wh40k.com"}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test2/settings/Mail/install", headers=headers, data=data
)
self.assertEqual(output.status_code, 401)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
)
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
示例8: test_get_pull_request_ready_branch_no_repo
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_get_pull_request_ready_branch_no_repo(self):
"""Test the get_pull_request_ready_branch from the internal API
on the main repository
"""
with tests.user_set(self.app.application, tests.FakeUser()):
csrf_token = self.get_csrf()
# Query branches on an invalid repo
data = {"repo": "test", "namespace": "fake", "csrf_token": csrf_token}
output = self.app.post("/pv/pull-request/ready", data=data)
self.assertEqual(output.status_code, 404)
js_data = json.loads(output.get_data(as_text=True))
self.assertEqual(sorted(js_data.keys()), ["code", "message"])
self.assertEqual(js_data["code"], "ERROR")
self.assertEqual(
js_data["message"], "No repo found with the information provided"
)
示例9: test_get_pull_request_ready_branch_main_repo_no_branch
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_get_pull_request_ready_branch_main_repo_no_branch(self):
"""Test the get_pull_request_ready_branch from the internal API
on the main repository
"""
tests.create_projects(self.session)
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
# Get on with testing
user = tests.FakeUser()
user.username = "pingou"
with tests.user_set(self.app.application, user):
csrf_token = self.get_csrf()
# Query branches on the main repo
data = {"csrf_token": csrf_token, "repo": "test"}
output = self.app.post("/pv/pull-request/ready", data=data)
self.assertEqual(output.status_code, 200)
js_data = json.loads(output.get_data(as_text=True))
self.assertEqual(sorted(js_data.keys()), ["code", "task"])
self.assertEqual(js_data["code"], "OK")
示例10: test_remove_plugin_own_project_plugin_not_installed
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_remove_plugin_own_project_plugin_not_installed(self):
""" Test removing a plugin from a project for which you're the
main maintainer and the plugin is not installed.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token aaabbbcccddd"}
# Remove a plugin from /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/IRC/remove", headers=headers
)
self.assertEqual(output.status_code, 400)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EPLUGINNOTINSTALLED.name, data["error_code"]
)
self.assertEqual(
pagure.api.APIERROR.EPLUGINNOTINSTALLED.value, data["error"]
)
示例11: test_remove_plugin_someone_else_project_project_less_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_remove_plugin_someone_else_project_project_less_token(self):
""" Test removing a plugin from a project with which you have
nothing to do.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-less-foo"}
# Remove a plugin from /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Mail/" "remove", headers=headers
)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
data,
{
"plugin": {"mail_to": "serg@wh40k.com"},
"message": "Hook 'Mail' deactivated",
},
)
示例12: test_remove_plugin_project_specific_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_remove_plugin_project_specific_token(self):
""" Test removing a plugin from a project with a regular
project-specific token.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-specific-foo"}
# Remove a plugin from /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/settings/Mail/remove", headers=headers
)
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
data,
{
"plugin": {"mail_to": "serg@wh40k.com"},
"message": "Hook 'Mail' deactivated",
},
)
示例13: test_create_issue_own_project_no_data
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_create_issue_own_project_no_data(self):
""" Test creating a new ticket on a project for which you're the
main maintainer.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token aaabbbcccddd"}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post("/api/0/test/new_issue", headers=headers)
self.assertEqual(output.status_code, 400)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EINVALIDREQ.name, data["error_code"]
)
self.assertEqual(pagure.api.APIERROR.EINVALIDREQ.value, data["error"])
self.assertEqual(
data["errors"],
{
"issue_content": ["This field is required."],
"title": ["This field is required."],
},
)
示例14: test_create_issue_own_project_incomplete_data
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_create_issue_own_project_incomplete_data(self):
""" Test creating a new ticket on a project for which you're the
main maintainer.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token aaabbbcccddd"}
# complete data set
data = {"title": "test issue"}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test/new_issue", headers=headers, data=data
)
self.assertEqual(output.status_code, 400)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EINVALIDREQ.name, data["error_code"]
)
self.assertEqual(pagure.api.APIERROR.EINVALIDREQ.value, data["error"])
self.assertEqual(
data["errors"], {"issue_content": ["This field is required."]}
)
示例15: test_create_issue_invalid_project_specific_token
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import main [as 别名]
def test_create_issue_invalid_project_specific_token(self):
""" Test creating a new ticket on a project with a regular
project-specific token but for another project.
"""
# pingou's token with all the ACLs
headers = {"Authorization": "token project-specific-foo"}
# complete data set
data = {
"title": "test issue",
"issue_content": "This issue needs attention",
}
# Create an issue on /test/ where pingou is the main admin
output = self.app.post(
"/api/0/test2/new_issue", headers=headers, data=data
)
self.assertEqual(output.status_code, 401)
data = json.loads(output.get_data(as_text=True))
self.assertEqual(
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
)
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])