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_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 #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_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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: cli_driver_test.py    From hammer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_hier_dump_empty_constraints(self) -> None:
        """
        Test that hierarchical settings work properly even when no constraints
        are given.
        """
        # Set up some temporary folders for the unit test.
        syn_rundir = tempfile.mkdtemp()

        # Generate a config for testing.
        top_module = "dummy"
        config_path = os.path.join(syn_rundir, "run_config.json")

        def add_hier(d: Dict[str, Any]) -> Dict[str, Any]:
            output = deepdict(d)
            output["vlsi.inputs.default_output_load"] = 1
            output["vlsi.inputs.hierarchical.top_module"] = top_module
            output["vlsi.inputs.hierarchical.flat"] = "hierarchical"
            output["vlsi.inputs.hierarchical.config_source"] = "manual"
            output["vlsi.inputs.hierarchical.manual_modules"] = [
                {"mod1": ["m1s1", "m1s2"], "mod2": ["m2s1"], top_module: ["mod1", "mod2"]}]
            output["vlsi.inputs.hierarchical.manual_placement_constraints"] = []
            output["vlsi.inputs.hierarchical.constraints"] = []
            return output

        self.generate_dummy_config(
            syn_rundir, config_path, top_module, postprocessing_func=add_hier)

        # Check that running the CLIDriver executes successfully (code 0).
        with self.assertRaises(SystemExit) as cm:  # type: ignore
            CLIDriver().main(args=[
                "auto",  # action
                "-p", config_path,
                "--obj_dir", syn_rundir
            ])
        self.assertEqual(cm.exception.code, 0)

        # Cleanup
        shutil.rmtree(syn_rundir) 
Example #18
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_execute_with_missing_parameter(self):
        with temporal_file("{}") as request_file:
            e = main(["execute", "urlshortener:v1.url.get", request_file])
            self.assertEqual(0, e.status)
            self.assertIn('Missing required parameter "shortUrl"', e.err) 
Example #19
Source File: cli_driver_test.py    From hammer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_override_actions(self) -> None:
        """
        Test that we can override actions like synthesis_action etc in subclasses.
        """

        class OverriddenDriver(CLIDriver):
            synthesis_called = False  # type: bool

            def synthesis_action(self, driver: HammerDriver,
                                 append_error_func: Callable[[str], None]) -> Optional[Dict]:
                def post_run_func(driver: HammerDriver) -> None:
                    OverriddenDriver.synthesis_called = True

                return self.create_action(action_type="synthesis", extra_hooks=None, post_run_func=post_run_func)(
                    driver, append_error_func)

        # Set up some temporary folders for the unit test.
        syn_rundir = tempfile.mkdtemp()

        # Generate a config for testing.
        top_module = "dummy"
        config_path = os.path.join(syn_rundir, "run_config.json")
        self.generate_dummy_config(syn_rundir, config_path, top_module)

        # Check that running the CLIDriver executes successfully (code 0).
        with self.assertRaises(SystemExit) as cm:  # type: ignore
            OverriddenDriver().main(args=[
                "syn",  # action
                "-p", config_path,
                "--syn_rundir", syn_rundir,
                "--par_rundir", syn_rundir
            ])
        self.assertEqual(cm.exception.code, 0)

        # Check that our synthesis function got called.
        self.assertEqual(OverriddenDriver.synthesis_called, True)

        # Cleanup
        shutil.rmtree(syn_rundir) 
Example #20
Source File: cli_driver_test.py    From hammer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_syn_to_par_improper(self) -> None:
        """
        Test that appropriate error messages are raised when syn-to-par
        is used on a config that does not have outputs.
        """

        # Set up some temporary folders for the unit test.
        syn_rundir = tempfile.mkdtemp()
        par_rundir = tempfile.mkdtemp()

        # Generate a config for testing.
        top_module = "dummy"
        config_path = os.path.join(syn_rundir, "run_config.json")
        log_path = os.path.join(syn_rundir, "log.txt")
        self.generate_dummy_config(syn_rundir, config_path, top_module)

        with HammerLoggingCaptureContext() as c:
            # Running syn-to-par on a not-output config should fail.
            with self.assertRaises(SystemExit) as cm:  # type: ignore
                CLIDriver().main(args=[
                    "syn-to-par",  # action
                    "-p", config_path,
                    "--log", log_path,
                    "--syn_rundir", syn_rundir,
                    "--par_rundir", par_rundir
                ])
            self.assertEqual(cm.exception.code, 1)
        self.assertTrue(c.log_contains("Input config does not appear to contain valid synthesis outputs"))

        # Cleanup
        shutil.rmtree(syn_rundir)
        shutil.rmtree(par_rundir) 
Example #21
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_option_shows_usage_and_help_messages(self):
        e = main(["-h"])

        self.assertEqual(2, e.status)
        self.assertIn("usage: ", e.out)
        self.assertIn("positional arguments:", e.out)
        self.assertIn("{show,execute}", e.out)
        self.assertIn("optional arguments:", e.out) 
Example #22
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_execute(self):
        request = """{
            "key": "%s",
            "shortUrl": "http://goo.gl/Du5PSN"
        }""" % secrets.server_key

        with temporal_file(request) as request_file:
            e = main(["execute", "urlshortener:v1.url.get", request_file])
            self.assertEqual(0, e.status)
            response = load_json(e.out)
            self.assertEqual(set(["id", "kind", "longUrl", "status"]), set(response.keys()))
            self.assertEqual(response["status"], "OK") 
Example #23
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_exact_method_shows_request_and_response_details(self):
        e = main(["show", "youtube:v3.videos.list"])
        lines = e.out.splitlines()

        self.assertEqual(0, e.status)
        self.assertTrue("Request" in line for line in lines)
        self.assertTrue("Response" in line for line in lines) 
Example #24
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_partial_method_string_shows_matching_methods_sorted(self):
        e = main(["show", "youtube:v3.videos.li"])
        lines = e.out.splitlines()
        methods = [line.split()[0] for line in lines]

        self.assertEqual(0, e.status)
        self.assertIn("youtube:v3.videos.list", methods)
        self.assertNotIn("youtube:v3.videos.insert", methods)
        self.assertEqual(list(sorted(methods)), methods) 
Example #25
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_exact_resource_string_shows_all_methods_sorted(self):
        e = main(["show", "youtube:v3.videos"])
        lines = e.out.splitlines()
        methods = [line.split()[0] for line in lines]

        self.assertEqual(0, e.status)
        self.assertIn("youtube:v3.videos.list", methods)
        self.assertIn("youtube:v3.videos.insert", methods)
        self.assertEqual(list(sorted(methods)), methods) 
Example #26
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_partial_resource_string_shows_resources_sorted(self):
        e = main(["show", "youtube:v3.vid"])
        lines = e.out.splitlines()
        resources = [line.split()[0] for line in lines]

        self.assertEqual(0, e.status)
        self.assertNotIn("youtube:v3.activities", resources)
        self.assertIn("youtube:v3.videos", resources)
        self.assertEqual(list(sorted(resources)), resources) 
Example #27
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_exact_service_string_shows_all_resources_sorted(self):
        e = main(["show", "youtube:v3"])

        self.assertEqual(0, e.status)
        lines = e.out.splitlines()
        services = [line.split()[0] for line in lines]
        self.assertIn("youtube:v3.activities", services)
        self.assertIn("youtube:v3.videos", services)
        resources = [service.split(".")[-1] for service in services]
        self.assertEqual(list(sorted(resources)), resources) 
Example #28
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 #29
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_option_shows_version(self):
        e = main(["-v"])

        self.assertEqual(0, e.status)
        self.assertEqual(shoogle.__version__, e.out.strip()) 
Example #30
Source File: test_shoogle.py    From shoogle with GNU General Public License v3.0 5 votes vote down vote up
def test_main_with_empty_show_command_shows_all_services_sorted(self):
        e = main(["show"])

        self.assertEqual(0, e.status)
        lines = e.out.splitlines()
        services = [line.split()[0] for line in lines]
        self.assertIn("webmasters:v3", services)
        self.assertIn("youtube:v3", services)
        self.assertEqual(list(sorted(services)), services)