From bf0464d186efe631aa75435ffdefb6d2709ef0b4 Mon Sep 17 00:00:00 2001 From: Abhishek's Macbook Pro Date: Sun, 12 May 2024 04:20:30 +0530 Subject: [PATCH] updated test --- tests/src/commands/test_copy_test_path.py | 124 ++++++++++++---------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/tests/src/commands/test_copy_test_path.py b/tests/src/commands/test_copy_test_path.py index 4c5919b..e960d47 100644 --- a/tests/src/commands/test_copy_test_path.py +++ b/tests/src/commands/test_copy_test_path.py @@ -14,9 +14,7 @@ def setUp(self): def tearDown(self): pass - def test_copy_django_class_test_path( - self, - ): + def test_copy_django_class_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened @@ -25,23 +23,35 @@ def test_copy_django_class_test_path( pass test_file_view = self.test_file_view - test_file_view.sel().clear() - test_file_view.sel().add(sublime.Region(53, 63)) + with patch("sublime.load_settings") as mocked_load_settings, patch("os.path.exists") as mocked_os_path_exists: + + mocked_load_settings.return_value = { + "python_venv_path": "/Users/abhishek/venv/bin/activate", + "log_level": "debug", + "test_config": { + "enabled": True, + "test_framework": "pytest", + "working_directory": "/Users/abhishek/", + "test_runner_command": ["pytest"], + } + } + mocked_os_path_exists.return_value = True - selected_text = test_file_view.substr(test_file_view.sel()[0]) - self.assertEqual(selected_text, "MyTestCase") + test_file_view.sel().clear() + test_file_view.sel().add(sublime.Region(53, 63)) - test_file_view.run_command( - "py_rock", args={"action": "copy_test_path", "test": True}) + selected_text = test_file_view.substr(test_file_view.sel()[0]) + self.assertEqual(selected_text, "MyTestCase") - expected_import_statement = sublime.get_clipboard() - self.assertEqual( - expected_import_statement, "tests.fixtures.test_fixture.MyTestCase" - ) + test_file_view.run_command( + "py_rock", args={"action": "copy_test_path", "test": True}) - def test_copy_django_class_method_test_path( - self, - ): + expected_import_statement = sublime.get_clipboard() + self.assertEqual( + expected_import_statement, "tests/fixtures/test_fixture.py::MyTestCase" + ) + + def test_copy_django_class_method_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened @@ -50,24 +60,31 @@ def test_copy_django_class_method_test_path( pass test_file_view = self.test_file_view - test_file_view.sel().clear() - test_file_view.sel().add(sublime.Region(83, 105)) + with patch("PyRock.src.settings.SettingsTestConfigField._get_value") as mocked_get_test_config: - selected_text = test_file_view.substr(test_file_view.sel()[0]) - self.assertEqual(selected_text, "test_long_running_task") + mocked_get_test_config.return_value = { + "enabled": True, + "test_framework": "pytest", + "working_directory": PyRockConstants.PACKAGE_TEST_FIXTURES_DIR, + "test_runner_command": ["pytest"] + } + + test_file_view.sel().clear() + test_file_view.sel().add(sublime.Region(83, 105)) + + selected_text = test_file_view.substr(test_file_view.sel()[0]) + self.assertEqual(selected_text, "test_long_running_task") - test_file_view.run_command( - "py_rock", args={"action": "copy_test_path", "test": True}) + test_file_view.run_command( + "py_rock", args={"action": "copy_test_path", "test": True}) - expected_import_statement = sublime.get_clipboard() - self.assertEqual( - expected_import_statement, - "tests.fixtures.test_fixture.MyTestCase.test_long_running_task" - ) + expected_import_statement = sublime.get_clipboard() + self.assertEqual( + expected_import_statement, + "tests/fixtures/test_fixture.py::MyTestCase::test_long_running_task" + ) - def test_copy_django_individual_method_test_path( - self, - ): + def test_copy_django_individual_method_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened @@ -76,25 +93,30 @@ def test_copy_django_individual_method_test_path( pass test_file_view = self.test_file_view - test_file_view.sel().clear() - test_file_view.sel().add(sublime.Region(272, 286)) + with patch("PyRock.src.settings.SettingsTestConfigField._get_value") as mocked_get_test_config: - selected_text = test_file_view.substr(test_file_view.sel()[0]) - self.assertEqual(selected_text, "test_iam_alone") + mocked_get_test_config.return_value = { + "enabled": True, + "test_framework": "pytest", + "working_directory": PyRockConstants.PACKAGE_TEST_FIXTURES_DIR, + "test_runner_command": ["pytest"] + } + + test_file_view.sel().clear() + test_file_view.sel().add(sublime.Region(272, 286)) + + selected_text = test_file_view.substr(test_file_view.sel()[0]) + self.assertEqual(selected_text, "test_iam_alone") - test_file_view.run_command( - "py_rock", args={"action": "copy_test_path", "test": True}) + test_file_view.run_command( + "py_rock", args={"action": "copy_test_path", "test": True}) - expected_import_statement = sublime.get_clipboard() - self.assertEqual( - expected_import_statement, "tests.fixtures.test_fixture.test_iam_alone" - ) + expected_import_statement = sublime.get_clipboard() + self.assertEqual( + expected_import_statement, "tests/fixtures/test_fixture.py::test_iam_alone" + ) - # @patch("PyRock.src.settings.SettingsTestConfigField._get_value") - def test_copy_pytest_class_test_path( - self, - # mocked_get_test_config, - ): + def test_copy_pytest_class_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened @@ -125,11 +147,7 @@ def test_copy_pytest_class_test_path( expected_import_statement, "tests/fixtures/test_fixture.py::MyTestCase" ) - # @patch("PyRock.src.settings.SettingsTestConfigField._get_value") - def test_copy_pytest_class_method_test_path( - self, - # mocked_get_test_config, - ): + def test_copy_pytest_class_method_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened @@ -161,11 +179,7 @@ def test_copy_pytest_class_method_test_path( "tests/fixtures/test_fixture.py::MyTestCase::test_long_running_task" ) - # @patch("PyRock.src.settings.SettingsTestConfigField._get_value") - def test_copy_pytest_individual_method_test_path( - self, - # mocked_get_test_config, - ): + def test_copy_pytest_individual_method_test_path(self): sublime.set_timeout_async(self._open_test_fixture_file, 0) try: # Wait 4 second to make sure test fixture file has opened