Esempio n. 1
0
 def test_it_can_take_profiler_options_as_argument(self):
     args = [
         '-p', 'pg_name', '-r', 'eu-north-1', '-c', 'test-cred-profile',
         '--log', 'info', self.script_file_name, '--where', 'zoo', 'foo'
     ]
     main(input_args=args, start_profiler=lambda *rargs: True)
     assert self._script_was_called()
Esempio n. 2
0
 def test_it_does_not_create_profiler_if_enabled_is_false(self):
     args = [
         '-p', 'pg_name', self.script_file_name, '--where', 'zoo', 'foo'
     ]
     env = {ENABLED_ENV: 'false'}
     main(input_args=args, env=env)
     from codeguru_profiler_agent.__main__ import profiler
     assert profiler is None
Esempio n. 3
0
 def test_it_passes_script_arguments_and_checks_the_values_of_all_arguments_when_no_client_arguments_are_set(
         self):
     args = [self.script_file_name]
     with pytest.raises(ValueError) as ve:
         main(input_args=args)
     # Depending on how the unit tests are run, the argument can be:
     # - setup.py' if run through an internal build tool or
     # - '/../.../pytest' if run with pytest.
     assert str(ve.value).endswith("['setup.py']") or str(
         ve.value).endswith("pytest']")
Esempio n. 4
0
 def test_it_creates_profiler_if_enabled_is_true(self):
     args = [
         '-p', 'pg_name', self.script_file_name, '--where', 'zoo', 'foo'
     ]
     env = {ENABLED_ENV: 'true'}
     main(input_args=args, env=env)
     from codeguru_profiler_agent import Profiler
     from codeguru_profiler_agent.__main__ import profiler
     assert profiler is not None
     assert isinstance(profiler, Profiler)
Esempio n. 5
0
    def test_it_creates_profiler_with_provided_argument(self):
        args = [
            '-p', 'pg_name', '-r', 'eu-north-1', '-c', 'test-cred-profile',
            '--log', 'info', self.script_file_name, '--where', 'zoo', 'foo'
        ]
        ran_start_profiler = False

        def mock_start_profiler(options, env):
            nonlocal ran_start_profiler
            ran_start_profiler = True
            assert options.profiling_group_name == 'pg_name'
            assert options.region == 'eu-north-1'
            assert options.credential_profile == 'test-cred-profile'
            assert env == os.environ

        main(args, start_profiler=mock_start_profiler)
        assert ran_start_profiler
Esempio n. 6
0
 def test_it_can_run_a_module(self):
     args = ['-m', self.script_file_name[:-3], '--where', 'zoo', 'foo']
     main(input_args=args)
     assert self._script_was_called()
Esempio n. 7
0
 def test_it_can_take_profiler_options_from_env(self):
     args = [self.script_file_name, '--where', 'zoo', 'foo']
     env = {PG_NAME_ENV: 'pg_name'}
     main(input_args=args, env=env)
     assert self._script_was_called()
Esempio n. 8
0
 def test_it_exits_if_no_arguments(self):
     with pytest.raises(SystemExit) as se:
         main(input_args=[])
     assert se.value.code == 2
Esempio n. 9
0
 def test_it_passes_script_arguments_and_checks_the_values_of_all_arguments(
         self):
     args = [self.script_file_name, 'one', 'two', 'three']
     with pytest.raises(ValueError) as ve:
         main(input_args=args)
     assert str(ve.value).endswith("'one', 'two', 'three']")
Esempio n. 10
0
 def test_it_starts_given_module_with_script_arguments(self):
     args = ['-m', self.script_file_name[:-3], '--where', 'zoo', 'foo']
     main(input_args=args)
     assert self._script_was_called()