Skip to content

Commit

Permalink
update warning type and test
Browse files Browse the repository at this point in the history
  • Loading branch information
klmcadams committed Dec 18, 2024
1 parent 8f770c6 commit f49bd61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def open(self, db_file, remove_lock=False):
if lock_file.exists():
warnings.warn(
f"Removing the lock file, {lock_file}, before opening the project. \
This may corrupt the project file."
This may corrupt the project file.",
UserWarning,
stacklevel=2,
)
lock_file.unlink()

Expand Down
5 changes: 3 additions & 2 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
# Assert the lock file exists after opening it
assert lock_file.exists()

# Remove the lock file before opening the project file
embedded_app.open(project_file, remove_lock=True)
with pytest.warns(UserWarning):
# Remove the lock file before opening the project file
embedded_app.open(project_file, remove_lock=True)

# Assert the lock file has been removed
assert not lock_file.exists()

Check failure on line 455 in tests/embedding/test_app.py

View workflow job for this annotation

GitHub Actions / Test Report 3.12

test_app.test_app_lock_file_open

AssertionError: assert not True + where True = exists() + where exists = PosixPath('/tmp/tmp892u0uku_Mech_Files/.mech_lock').exists
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:242
Software build date: 06/03/2024 09:35:09

tmp_path = PosixPath('/tmp/pytest-of-root/pytest-0/test_app_lock_file_open0')

    @pytest.mark.embedding
    def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
        """Test the lock file is removed on open if remove_lock=True."""
        embedded_app.DataModel.Project.Name = "PROJECT 1"
        project_file = os.path.join(tmp_path, f"{NamedTemporaryFile().name}.mechdat")
        embedded_app.save_as(project_file)
        with pytest.raises(Exception):
            embedded_app.save_as(project_file)
        embedded_app.save_as(project_file, overwrite=True)
    
        lock_file = Path(embedded_app.DataModel.Project.ProjectDirectory) / ".mech_lock"
    
        # Do not remove the lock file before opening the project file
        embedded_app.open(project_file)
    
        # Assert the lock file exists after opening it
        assert lock_file.exists()
    
        with pytest.warns(UserWarning):
            # Remove the lock file before opening the project file
            embedded_app.open(project_file, remove_lock=True)
    
        # Assert the lock file has been removed
>       assert not lock_file.exists()
E       AssertionError: assert not True
E        +  where True = exists()
E        +    where exists = PosixPath('/tmp/tmp892u0uku_Mech_Files/.mech_lock').exists

tests/embedding/test_app.py:455: AssertionError

Check failure on line 455 in tests/embedding/test_app.py

View workflow job for this annotation

GitHub Actions / Test Report 3.11

test_app.test_app_lock_file_open

AssertionError: assert not True + where True = exists() + where exists = PosixPath('/tmp/tmph9hsi0vf_Mech_Files/.mech_lock').exists
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:242
Software build date: 06/03/2024 09:35:09

tmp_path = PosixPath('/tmp/pytest-of-root/pytest-0/test_app_lock_file_open0')

    @pytest.mark.embedding
    def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
        """Test the lock file is removed on open if remove_lock=True."""
        embedded_app.DataModel.Project.Name = "PROJECT 1"
        project_file = os.path.join(tmp_path, f"{NamedTemporaryFile().name}.mechdat")
        embedded_app.save_as(project_file)
        with pytest.raises(Exception):
            embedded_app.save_as(project_file)
        embedded_app.save_as(project_file, overwrite=True)
    
        lock_file = Path(embedded_app.DataModel.Project.ProjectDirectory) / ".mech_lock"
    
        # Do not remove the lock file before opening the project file
        embedded_app.open(project_file)
    
        # Assert the lock file exists after opening it
        assert lock_file.exists()
    
        with pytest.warns(UserWarning):
            # Remove the lock file before opening the project file
            embedded_app.open(project_file, remove_lock=True)
    
        # Assert the lock file has been removed
>       assert not lock_file.exists()
E       AssertionError: assert not True
E        +  where True = exists()
E        +    where exists = PosixPath('/tmp/tmph9hsi0vf_Mech_Files/.mech_lock').exists

tests/embedding/test_app.py:455: AssertionError

Check failure on line 455 in tests/embedding/test_app.py

View workflow job for this annotation

GitHub Actions / Test Report 3.10

test_app.test_app_lock_file_open

AssertionError: assert not True + where True = exists() + where exists = PosixPath('/tmp/tmpaeyuvo49_Mech_Files/.mech_lock').exists
Raw output
embedded_app = Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:242
Software build date: 06/03/2024 09:35:09

tmp_path = PosixPath('/tmp/pytest-of-root/pytest-0/test_app_lock_file_open0')

    @pytest.mark.embedding
    def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
        """Test the lock file is removed on open if remove_lock=True."""
        embedded_app.DataModel.Project.Name = "PROJECT 1"
        project_file = os.path.join(tmp_path, f"{NamedTemporaryFile().name}.mechdat")
        embedded_app.save_as(project_file)
        with pytest.raises(Exception):
            embedded_app.save_as(project_file)
        embedded_app.save_as(project_file, overwrite=True)
    
        lock_file = Path(embedded_app.DataModel.Project.ProjectDirectory) / ".mech_lock"
    
        # Do not remove the lock file before opening the project file
        embedded_app.open(project_file)
    
        # Assert the lock file exists after opening it
        assert lock_file.exists()
    
        with pytest.warns(UserWarning):
            # Remove the lock file before opening the project file
            embedded_app.open(project_file, remove_lock=True)
    
        # Assert the lock file has been removed
>       assert not lock_file.exists()
E       AssertionError: assert not True
E        +  where True = exists()
E        +    where exists = PosixPath('/tmp/tmpaeyuvo49_Mech_Files/.mech_lock').exists

tests/embedding/test_app.py:455: AssertionError

0 comments on commit f49bd61

Please sign in to comment.