Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace os.curdir with __file__ #2278

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tests/test_ToolboxUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Unit tests for ToolboxUI class.
"""

from collections import namedtuple
from pathlib import Path
from contextlib import contextmanager
from tempfile import TemporaryDirectory
import unittest
Expand Down Expand Up @@ -162,10 +162,8 @@ def test_open_project(self):
Data Connection 'b', Tool 'c', and View 'd'. The items are connected
a->b->c->d.
"""
project_dir = os.path.abspath(os.path.join(os.curdir, "tests", "test_resources", "Project Directory"))
if not os.path.exists(project_dir):
self.skipTest("Test project directory '{0}' does not exist".format(project_dir))
return
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
"spinetoolbox.project.create_dir"
Expand Down Expand Up @@ -226,7 +224,8 @@ def test_open_project(self):
self.assertTrue(g.has_edge("c", "d"))

def test_init_project(self):
project_dir = os.path.abspath(os.path.join(os.curdir, "tests", "test_resources", "Project Directory"))
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
"spinetoolbox.project.create_dir"
Expand Down Expand Up @@ -658,18 +657,19 @@ def test_add_and_remove_specification(self):

Note: Test 'project.json' file should not have any
specifications when this test starts and ends."""
project_dir = os.path.abspath(os.path.join(os.curdir, "tests", "test_resources", "Project Directory"))
if not os.path.exists(project_dir):
self.skipTest("Test project directory '{0}' does not exist".format(project_dir))
return
project_dir = os.path.abspath(os.path.join(str(Path(__file__).parent), "test_resources", "Project Directory"))
self.assertTrue(os.path.exists(project_dir))
self.assertIsNone(self.toolbox.project())
with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
"spinetoolbox.ui_main.ToolboxUI.update_recent_projects"
):
self.toolbox.open_project(project_dir)
# Tool spec model must be empty at this point
self.assertEqual(0, self.toolbox.specification_model.rowCount())
tool_spec_path = os.path.abspath(os.path.join(os.curdir, "tests", "test_resources", "test_tool_spec.json"))
tool_spec_path = os.path.abspath(
os.path.join(str(Path(__file__).parent), "test_resources", "test_tool_spec.json")
)
self.assertTrue(os.path.exists(tool_spec_path))
# Add a Tool spec to 'project.json' file
with mock.patch("spinetoolbox.ui_main.QFileDialog.getOpenFileName") as mock_filename, mock.patch(
"spine_items.tool.tool_specifications.ToolSpecification.save"
Expand Down