Python unittest.main() Examples

The following are 30 code examples of unittest.main(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module unittest , or try the search function .
Example #1
Source File: test_program.py    From jawfish with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: test_test_utils.py    From Zopkio with Apache License 2.0 6 votes vote down vote up
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') 
Example #3
Source File: test_pagure_flask_api_plugins_install.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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."]}
        ) 
Example #4
Source File: test_pagure_flask_api_plugins_install.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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",
            },
        ) 
Example #5
Source File: test_pagure_flask_api_plugins_install.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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",
            },
        ) 
Example #6
Source File: test_pagure_flask_api_plugins_install.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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",
            },
        ) 
Example #7
Source File: test_pagure_flask_api_plugins_install.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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"]) 
Example #8
Source File: test_pagure_flask_internal.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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"
        ) 
Example #9
Source File: test_pagure_flask_internal.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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") 
Example #10
Source File: test_pagure_flask_api_plugins_remove.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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"]
        ) 
Example #11
Source File: test_pagure_flask_api_plugins_remove.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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",
            },
        ) 
Example #12
Source File: test_pagure_flask_api_plugins_remove.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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",
            },
        ) 
Example #13
Source File: test_pagure_flask_api_issue_create.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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."],
            },
        ) 
Example #14
Source File: test_pagure_flask_api_issue_create.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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."]}
        ) 
Example #15
Source File: test_pagure_flask_api_issue_create.py    From pagure with GNU General Public License v2.0 6 votes vote down vote up
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"]) 
Example #16
Source File: cli_driver_test.py    From hammer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_syn_to_par_with_output(self, config_path: str, syn_rundir: str,
                                   par_rundir: str,
                                   syn_out_path: str,
                                   syn_to_par_out_path: str) -> None:
        # Check that running the CLIDriver executes successfully (code 0).
        with self.assertRaises(SystemExit) as cm:  # type: ignore
            CLIDriver().main(args=[
                "syn",  # action
                "-p", config_path,
                "--output", syn_out_path,
                "--syn_rundir", syn_rundir,
                "--par_rundir", par_rundir
            ])
        self.assertEqual(cm.exception.code, 0)
        # Now run syn-to-par with the main config as well as the outputs.
        with self.assertRaises(SystemExit) as cm:  # type: ignore
            CLIDriver().main(args=[
                "syn-to-par",  # action
                "-p", config_path,
                "-p", syn_out_path,
                "--output", syn_to_par_out_path,
                "--syn_rundir", syn_rundir,
                "--par_rundir", par_rundir
            ])
        self.assertEqual(cm.exception.code, 0) 
Example #17
Source File: telegram.py    From fishroom with GNU General Public License v3.0 5 votes vote down vote up
def main():
    if "telegram" not in config:
        return

    from .runner import run_threads
    tg, im2fish_bus, fish2im_bus = init()
    run_threads([
        (Telegram2FishroomThread, (tg, im2fish_bus, ), ),
        (Fishroom2TelegramThread, (tg, fish2im_bus, ), ),
    ]) 
Example #18
Source File: telegram.py    From fishroom with GNU General Public License v3.0 5 votes vote down vote up
def test():
    unittest.main()

    from .photostore import VimCN

    tele = Telegram(config['telegram']['token'],
                    nick_store=MemNickStore(), photo_store=VimCN())
    # tele.send_msg('user#67655173', 'hello')
    tele.send_photo('-34678255', open('test.png', 'rb').read())
    tele.send_msg('-34678255', "Back!")
    for msg in tele.message_stream():
        print(msg.dumps())
        tele.send_msg(msg.receiver, msg.content)
    return 
Example #19
Source File: test_hanlp.py    From pyhanlp with Apache License 2.0 5 votes vote down vote up
def test():
    unittest.main() 
Example #20
Source File: test_multithread.py    From pyhanlp with Apache License 2.0 5 votes vote down vote up
def test():
    unittest.main() 
Example #21
Source File: test_OpticalSystem.py    From EXOSIMS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_init_iwa_owa(self):
        r"""Test of initialization and __init__ -- IWA, OWA.

        Method: We instantiate OpticalSystem objects and verify 
        various IWA/OWA relationships.
        """
        for specs in [specs_default, specs_simple, specs_multi]:
            # the input dict is modified in-place -- so copy it
            our_specs = deepcopy(specs)
            # set root object IWA and OWA in conflict
            our_specs['IWA'] = 10
            our_specs['OWA'] = 1
            with self.assertRaises(AssertionError):
                optsys = self.fixture(**deepcopy(our_specs))
        for specs in [specs_default, specs_simple, specs_multi]:
            # various settings of sub-object IWA and OWA
            for IWA, OWA in zip([1, 1, 10, 10, 20, 20], [5, 15, 5, 15, 5, 15]):
                # the input dict is modified in-place -- so copy it
                our_specs = deepcopy(specs)
                # set sub-object IWA and OWA 
                for syst in our_specs['starlightSuppressionSystems']:
                    syst['IWA'] = IWA
                    syst['OWA'] = OWA
                if IWA < OWA:
                    # will succeed in this case
                    optsys = self.fixture(**deepcopy(our_specs))
                    # they must propagate up to main object
                    self.assertTrue(optsys.OWA.value == OWA)
                    self.assertTrue(optsys.IWA.value == IWA)
                else:
                    # they propagate up, and cause a failure
                    with self.assertRaises(AssertionError):
                        optsys = self.fixture(**deepcopy(our_specs)) 
Example #22
Source File: test_TargetList.py    From EXOSIMS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_main_sequence_filter(self):
        n0 = self.targetlist.nStars
        self.targetlist.main_sequence_filter()
        #print self.targetlist.nStars
        #Check that no stars fall outside main sequence strip
        self.assertEqual( np.any((self.targetlist.BV < 0.74) & (self.targetlist.MV > 6*self.targetlist.BV+1.8)) , False)
        self.assertEqual( np.any((self.targetlist.BV >= 0.74) & (self.targetlist.BV < 1.37) & (self.targetlist.MV > 4.3*self.targetlist.BV+3.05)) , False)
        self.assertEqual( np.any((self.targetlist.BV >= 1.37) & (self.targetlist.MV > 18*self.targetlist.BV-15.7)) , False)
        self.assertEqual( np.any((self.targetlist.BV < 0.87) & (self.targetlist.MV < -8*(self.targetlist.BV-1.35)**2+7.01)) , False)
        self.assertEqual( np.any((self.targetlist.BV >= 0.87) & (self.targetlist.BV < 1.45) & (self.targetlist.MV > 5*self.targetlist.BV+0.81)) , False)
        self.assertEqual( np.any((self.targetlist.BV >= 1.45) & (self.targetlist.MV < 18*self.targetlist.BV-18.04)) , False)
        #check that filtered target list does not have repeating elements
        import collections
        compare = lambda x, y: collections.Counter(x) == collections.Counter(y)
        self.assertEqual( compare(list(set(self.targetlist.Name)), list(self.targetlist.Name)) , True) 
Example #23
Source File: test_all.py    From myhdl with GNU Lesser General Public License v2.1 5 votes vote down vote up
def main():
    unittest.main(defaultTest='suite',
                  testRunner=unittest.TextTestRunner(verbosity=2)) 
Example #24
Source File: test_all.py    From myhdl with GNU Lesser General Public License v2.1 5 votes vote down vote up
def main():
    unittest.main(defaultTest='suite',
                  testRunner=unittest.TextTestRunner(verbosity=2)) 
Example #25
Source File: test_all.py    From myhdl with GNU Lesser General Public License v2.1 5 votes vote down vote up
def main():
    unittest.main(defaultTest='suite',
                  testRunner=unittest.TextTestRunner(verbosity=2)) 
Example #26
Source File: test_all.py    From myhdl with GNU Lesser General Public License v2.1 5 votes vote down vote up
def main():
    unittest.main(defaultTest='suite',
                  testRunner=unittest.TextTestRunner(verbosity=2)) 
Example #27
Source File: test_leveldb.py    From leveldb-py with MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser("run tests")
    parser.add_argument("--runs", type=int, default=1)
    args = parser.parse_args()
    for _ in xrange(args.runs):
        unittest.main(argv=sys.argv[:1], exit=False) 
Example #28
Source File: test_program.py    From jawfish with MIT License 5 votes vote down vote up
def test_NonExit(self):
        program = unittest.main(exit=False,
                                argv=["foobar"],
                                testRunner=unittest.TextTestRunner(stream=io.StringIO()),
                                testLoader=self.FooBarLoader())
        self.assertTrue(hasattr(program, 'result')) 
Example #29
Source File: test_program.py    From jawfish with MIT License 5 votes vote down vote up
def test_Exit(self):
        self.assertRaises(
            SystemExit,
            unittest.main,
            argv=["foobar"],
            testRunner=unittest.TextTestRunner(stream=io.StringIO()),
            exit=True,
            testLoader=self.FooBarLoader()) 
Example #30
Source File: test_program.py    From jawfish with MIT License 5 votes vote down vote up
def test_ExitAsDefault(self):
        self.assertRaises(
            SystemExit,
            unittest.main,
            argv=["foobar"],
            testRunner=unittest.TextTestRunner(stream=io.StringIO()),
            testLoader=self.FooBarLoader())