コード例 #1
0
    def test_warntimer_waits_until_30_seconds_before_roundtimelimit(self):
        setup_cvar("roundtimelimit", "180")
        patch(time.sleep, lambda _int: None)

        undecorated(self.warner.warntimer)(self.warner)

        verify(time).sleep(150)
コード例 #2
0
    async def test_on_message_without_message(self):
        patch(minqlx.CHAT_CHANNEL, "reply", lambda msg: None)
        when2(minqlx.CHAT_CHANNEL.reply, any).thenReturn(None)

        await self.discord.on_message(None)

        verify(minqlx.CHAT_CHANNEL, times=0).reply(any)
コード例 #3
0
    def test_warntimer_sets_thread_name(self):
        setup_cvar("roundtimelimit", "180")
        patch(time.sleep, lambda _int: None)

        undecorated(self.warner.warntimer)(self.warner)

        assert_that(self.warner.warner_thread_name, any_(str))
コード例 #4
0
    def test_old_submission_is_cleared_given_it_already_exists(self):
        patch(shutil.rmtree, lambda str: '')
        when(os.path).exists(self.submission_path).thenReturn(True)

        self.repository.clone(self.submission)

        verify(shutil).rmtree(self.submission_path)
コード例 #5
0
    def testPatch(self):
        dummy = mock()
        patch('os.path.exists', dummy)

        import os.path
        assert os.path.exists('/Foo') is None

        verify(dummy).__call__('/Foo')
コード例 #6
0
    def testPatch(self):
        dummy = mock()
        patch('os.path.exists', dummy)

        import os.path
        assert os.path.exists('/Foo') is None

        verify(dummy).__call__('/Foo')
コード例 #7
0
def test_miktex_setup_edit_mpm_add_line(mpm_file: Path, miktex: MikTex):
    mpm_file.write_text("""some pre-existing content
[MPM]
""",
                        encoding='utf8')
    patch(MikTex, 'version', 'test')
    miktex.setup()
    assert mpm_file.read_text(encoding='utf8') == """some pre-existing content
コード例 #8
0
    async def test_on_message_too_short_message(self):
        message = mocked_message(content="",
                                 channel=self.relay_channel())

        patch(minqlx.CHAT_CHANNEL, "reply", lambda msg: None)
        when2(minqlx.CHAT_CHANNEL.reply, any).thenReturn(None)

        await self.discord.on_message(message)

        verify(minqlx.CHAT_CHANNEL, times=0).reply(any)
コード例 #9
0
    async def test_on_message_in_wrong_channel(self):
        message = mocked_message(content="some chat message",
                                 channel=self.triggered_channel())

        patch(minqlx.CHAT_CHANNEL, "reply", lambda msg: None)
        when2(minqlx.CHAT_CHANNEL.reply, any).thenReturn(None)

        await self.discord.on_message(message)

        verify(minqlx.CHAT_CHANNEL, times=0).reply(any)
コード例 #10
0
    def testPatch3(self):
        rex = Dog()

        def f(self, sound):
            return self.bark_hard(sound)

        f = newmethod(f, rex)
        patch(rex.bark, f)

        assert rex.bark('Miau') == 'Miau!'
コード例 #11
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
    def testPatch3(self):
        rex = Dog()

        def f(self, sound):
            return self.bark_hard(sound)

        f = newmethod(f, rex)
        patch(rex.bark, f)

        assert rex.bark('Miau') == 'Miau!'
コード例 #12
0
    async def test_on_message_by_user_with_nickname(self):
        message = mocked_message(content="some chat message",
                                 user=mocked_user(name="Sender", nick="SenderNick"),
                                 channel=self.relay_channel())

        patch(minqlx.CHAT_CHANNEL, "reply", lambda msg: None)
        when2(minqlx.CHAT_CHANNEL.reply, any).thenReturn(None)

        await self.discord.on_message(message)

        verify(minqlx.CHAT_CHANNEL).reply("[DISCORD] ^6SenderNick^7:^2 some chat message")
コード例 #13
0
def test_miktex_setup_edit_mpm_line(mpm_file: Path, miktex: MikTex):
    mpm_file.write_text(""";;; DO NOT EDIT THIS FILE!


[MPM]
AutoInstall=0

""",
                        encoding='utf8')
    patch(MikTex, 'version', 'test')
    miktex.setup()
    assert mpm_file.read_text(encoding='utf8') == """;;; DO NOT EDIT THIS FILE!
コード例 #14
0
    def test_sign(self, tx):
        SIGNATURE = 'signature'
        DUMMY_KEY = 'key'

        def sign_func(hash, key):
            if hash == tx.hash and key == DUMMY_KEY:
                return SIGNATURE
            raise Exception('unexpected input to patch sign_func')

        patch('plasma_cash.child_chain.transaction.sign', sign_func)
        tx.sign(DUMMY_KEY)
        assert tx.sig == SIGNATURE
コード例 #15
0
ファイル: test_mirror.py プロジェクト: yashchow/opengrok
def test_disabled_command_api():
    """
    Test that mirror_project() calls call_rest_api() if API
    call is specified in the configuration for disabled project.
    """
    with patch(opengrok_tools.utils.mirror.call_rest_api,
               lambda a, b, c: mock(spec=requests.Response)):
        project_name = "foo"
        config = {
            DISABLED_CMD_PROPERTY: {
                COMMAND_PROPERTY:
                ["http://localhost:8080/source/api/v1/foo", "POST", "data"]
            },
            PROJECTS_PROPERTY: {
                project_name: {
                    DISABLED_PROPERTY: True
                }
            }
        }

        assert mirror_project(config, project_name, False, None,
                              None) == CONTINUE_EXITVAL
        verify(opengrok_tools.utils.mirror). \
            call_rest_api(config.get(DISABLED_CMD_PROPERTY),
                          PROJECT_SUBST, project_name)
コード例 #16
0
def test_disabled_command_api():
    """
    Test that mirror_project() calls call_rest_api() if API
    call is specified in the configuration for disabled project.
    """
    def mock_call_rest_api(command, b, http_headers=None, timeout=None, api_timeout=None):
        return mock(spec=requests.Response)

    with patch(opengrok_tools.utils.mirror.call_rest_api,
               mock_call_rest_api):
        project_name = "foo"
        config = {
            DISABLED_CMD_PROPERTY: {
                CALL_PROPERTY: {
                    "uri": "http://localhost:8080/source/api/v1/foo",
                    "method": "POST", "data": "data"}
            },
            PROJECTS_PROPERTY: {
                project_name: {DISABLED_PROPERTY: True}
            }
        }

        assert mirror_project(config, project_name, False, False,
                              None, None) == CONTINUE_EXITVAL
        verify(opengrok_tools.utils.mirror). \
            call_rest_api(ANY,
                          {PROJECT_SUBST: project_name},
                          http_headers=None, timeout=None, api_timeout=None)
コード例 #17
0
def test_main__successful_run():
    sys.argv = ['', '-m=./tests/data/test.json', '-o=/tmp/output.csv']
    with open('./tests/data/test.html') as f:
        html_doc = f.read()
        with patch(http_client.HTTPClient, 'get_html', lambda params: html_doc):
            main()

            assert os.path.exists('/tmp/output.csv')
コード例 #18
0
def test_dosync_check_config_empty(check_config, expected_times):
    commands = []
    with patch(pool.Pool.map, lambda x, y, z: []):
        assert do_sync(logging.INFO,
                       commands,
                       None, ["foo", "bar"], [],
                       "http://localhost:8080/source",
                       42,
                       check_config=check_config) == SUCCESS_EXITVAL
        verify(pool.Pool, times=expected_times).map(ANY, ANY, ANY)
コード例 #19
0
def test_successful_run(caplog):
    caplog.set_level(20)

    def _fake_monitor(context):
        context.return_code = 0

    when(sarge.Command).run(...)
    test_exe = pathlib.Path('./test.exe')
    when(_run).find_executable('test').thenReturn(test_exe)
    patch(_run.monitor_running_process, _fake_monitor)
    _run.run('test')
    verifyStubbedInvocationsAreUsed()
    assert [
        ('elib_run.process', 20,
         f'"{test_exe.absolute()}" in "{test_exe.parent.absolute()}": running'
         ),
        ('elib_run.process', 20,
         f'"{test_exe.absolute()}" in "{test_exe.parent.absolute()}": success: 0'
         ),
    ] == caplog.record_tuples
コード例 #20
0
def test_cov_propagate():
    x = np.array([1, 1, 1, 1, 1, 1])
    epoch_t = None
    prop_params = None
    dr = .1
    dv = .005
    delta = np.array([dr, dr, dr, dv, dv, dv])
    p_i = np.ones((6, 6))

    with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
        when(covariance_propagator).dx_dx0(x, epoch_t, prop_params,
                                           delta).thenReturn(np.eye(6))
        p_t = cov_propagate(x, epoch_t, prop_params, p_i)
    assert np.array_equal(p_i, p_t)
コード例 #21
0
def test_convert_obs_from_ecef_to_eci():
    input_pos = [1 * u.km, 2 * u.km, 3 * u.km]
    output_pos = np.array([0, 0, 0])
    epoch = None
    obs_values = None
    obs_type = None

    input = Observation(input_pos, Frames.ECEF, epoch, obs_values, obs_type)
    with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
        when(cleaning).ecef_to_eci(input_pos, epoch).thenReturn(np.array(output_pos))
    expected = Observation(output_pos, Frames.ECI, epoch, obs_values, obs_type)
    actual = convert_obs_from_ecef_to_eci(input)
    assert np.array_equal(expected.position, actual.position)
    assert expected.frame == actual.frame
コード例 #22
0
def test_dx_dx0():
    x = np.array([10, 20, 30, 40, 50, 60])
    delta = np.array([1, 2, 3, 4, 5, 6])
    epoch_t = None
    params = None

    expected = np.array([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12],
                         [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24],
                         [25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36]])

    with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
        when(covariance_propagator).state_propagate(
            np.array([11, 20, 30, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([2, 28, 78, 152, 250, 372]))
        when(covariance_propagator).state_propagate(
            np.array([9, 20, 30, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        when(covariance_propagator).state_propagate(
            np.array([10, 22, 30, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([4, 32, 84, 160, 260, 384]))
        when(covariance_propagator).state_propagate(
            np.array([10, 18, 30, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 33, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([6, 36, 90, 168, 270, 396]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 27, 40, 50, 60]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 44, 50, 60]), epoch_t,
            params).thenReturn(np.array([8, 40, 96, 176, 280, 408]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 36, 50, 60]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 40, 55, 60]), epoch_t,
            params).thenReturn(np.array([10, 44, 102, 184, 290, 420]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 40, 45, 60]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 40, 50, 66]), epoch_t,
            params).thenReturn(np.array([12, 48, 108, 192, 300, 432]))
        when(covariance_propagator).state_propagate(
            np.array([10, 20, 30, 40, 50, 54]), epoch_t,
            params).thenReturn(np.array([0, 0, 0, 0, 0, 0]))
        result = dx_dx0(x, epoch_t, params, delta)
    assert np.array_equal(expected, result)
コード例 #23
0
ファイル: test_restful.py プロジェクト: zzmjohn/opengrok
def test_headers_timeout_requests():
    """
    Test that headers and timeout parameters from do_call_api() are passed
    to the appropriate function in the requests module.
    Currently done for the GET HTTP verb only.
    """

    uri = "http://foo:8080"
    headers = {"foo": "bar"}
    timeout = 44

    def mock_requests_get(uri, **kwargs):
        return mock(spec=requests.Response)

    with patch(requests.get, mock_requests_get):
        do_api_call("GET", uri, headers=headers, timeout=timeout)

        verify(requests).get(uri, data=None, params=None,
                             headers=headers, proxies=None,
                             timeout=timeout)
コード例 #24
0
def test_derivative():
    x = np.array([10, 20, 30, 40, 50, 60])
    delta = np.array([1, 2, 3, 4, 5, 6])
    dt = 1
    epoch_obs = None
    observation = Observation(None, None, epoch_obs, None, None)
    params = None
    with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
        when(core).state_propagate(np.array([11, 20, 30, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([11, 20, 30, 40, 50, 60]))
        when(core).state_propagate(np.array([9, 20, 30, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([9, 20, 30, 40, 50, 60]))
        when(core).state_propagate(np.array([10, 22, 30, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 22, 30, 40, 50, 60]))
        when(core).state_propagate(np.array([10, 18, 30, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 18, 30, 40, 50, 60]))
        when(core).state_propagate(np.array([10, 20, 33, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 33, 40, 50, 60]))
        when(core).state_propagate(np.array([10, 20, 27, 40, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 27, 40, 50, 60]))
        when(core).state_propagate(np.array([10, 20, 30, 44, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 44, 50, 60]))
        when(core).state_propagate(np.array([10, 20, 30, 36, 50, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 36, 50, 60]))
        when(core).state_propagate(np.array([10, 20, 30, 40, 55, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 40, 55, 60]))
        when(core).state_propagate(np.array([10, 20, 30, 40, 45, 60]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 40, 45, 60]))
        when(core).state_propagate(np.array([10, 20, 30, 40, 50, 66]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 40, 50, 66]))
        when(core).state_propagate(np.array([10, 20, 30, 40, 50, 54]),
                                   epoch_obs, params).thenReturn(
                                       np.array([10, 20, 30, 40, 50, 54]))
        when(core).y(np.array([11, 20, 30, 40, 50, 60]),
                     observation).thenReturn(np.array([2, 4]))
        when(core).y(np.array([9, 20, 30, 40, 50, 60]),
                     observation).thenReturn(np.array([0, 0]))
        when(core).y(np.array([10, 22, 30, 40, 50, 60]),
                     observation).thenReturn(np.array([12, 16]))
        when(core).y(np.array([10, 18, 30, 40, 50, 60]),
                     observation).thenReturn(np.array([0, 0]))
        when(core).y(np.array([10, 20, 33, 40, 50, 60]),
                     observation).thenReturn(np.array([30, 36]))
        when(core).y(np.array([10, 20, 27, 40, 50, 60]),
                     observation).thenReturn(np.array([0, 0]))
        when(core).y(np.array([10, 20, 30, 44, 50, 60]),
                     observation).thenReturn(np.array([56, 64]))
        when(core).y(np.array([10, 20, 30, 36, 50, 60]),
                     observation).thenReturn(np.array([0, 0]))
        when(core).y(np.array([10, 20, 30, 40, 55, 60]),
                     observation).thenReturn(np.array([90, 100]))
        when(core).y(np.array([10, 20, 30, 40, 45, 60]),
                     observation).thenReturn(np.array([0, 0]))
        when(core).y(np.array([10, 20, 30, 40, 50, 66]),
                     observation).thenReturn(np.array([132, 144]))
        when(core).y(np.array([10, 20, 30, 40, 50, 54]),
                     observation).thenReturn(np.array([0, 0]))
        experimental = dy_dstate(x, delta, observation, params)
        theoretical = np.array(([1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12]))
        assert np.array_equal(theoretical, experimental)
コード例 #25
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
 def testPatch2(self):
     rex = Dog()
     patch(rex.bark, rex.bark_hard)
     assert rex.bark('Miau') == 'Miau!'
コード例 #26
0
    def testAddFnWithPatch(self):
        rex = Dog()

        patch(rex, 'newfn', lambda s: s)
        assert rex.newfn('Hi') == 'Hi'
コード例 #27
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
    def testAddFnWithPatch(self):
        rex = Dog()

        patch(rex, 'newfn', lambda s: s)
        assert rex.newfn('Hi') == 'Hi'
コード例 #28
0
 def testPatch2(self):
     rex = Dog()
     patch(rex.bark, rex.bark_hard)
     assert rex.bark('Miau') == 'Miau!'
コード例 #29
0
 def testPatch(self):
     rex = Dog()
     patch(rex.bark, lambda sound: sound + '!')
     assert rex.bark('Miau') == 'Miau!'
コード例 #30
0
    def setUp(self):
        patch(git.Repo.clone_from, lambda a, b: '')

        self.repository = GitRepository(self.BASE_PATH)
コード例 #31
0
ファイル: numpy_test.py プロジェクト: kaste/mockito-python
    def testEnsureNumpyArrayAllowedWhenStubbing(self):
        array = np.array([1, 2, 3])
        when(module).one_arg(array).thenReturn('yep')

        with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
            assert module.one_arg(array) == 'yep'
コード例 #32
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
 def testPatch(self):
     rex = Dog()
     patch(rex.bark, lambda sound: sound + '!')
     assert rex.bark('Miau') == 'Miau!'
コード例 #33
0
    def testEnsureNumpyArrayAllowedWhenStubbing(self):
        array = np.array([1, 2, 3])
        when(module).one_arg(array).thenReturn('yep')

        with patch(mockito.invocation.MatchingInvocation.compare, xcompare):
            assert module.one_arg(array) == 'yep'
コード例 #34
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
    def testPatch(self):
        patch(os.path.commonprefix, lambda m: 'yup')
        patch(os.path.commonprefix, lambda m: 'yep')

        assert os.path.commonprefix(Ellipsis) == 'yep'
コード例 #35
0
    def testPatch(self):
        patch(os.path.commonprefix, lambda m: 'yup')
        patch(os.path.commonprefix, lambda m: 'yep')

        assert os.path.commonprefix(Ellipsis) == 'yep'
コード例 #36
0
    def testWithPatchGivenThreeArgs(self):
        with patch(os.path, 'exists', lambda m: 'yup'):
            assert os.path.exists('foo') == 'yup'

        assert not os.path.exists('foo')
コード例 #37
0
ファイル: when2_test.py プロジェクト: kaste/mockito-python
    def testWithPatchGivenThreeArgs(self):
        with patch(os.path, 'exists', lambda m: 'yup'):
            assert os.path.exists('foo') == 'yup'

        assert not os.path.exists('foo')
コード例 #38
0
 def setup_qlstats_response(self, response):
     patch(requests.get, lambda _: response)
     spy(requests.get)