Skip to content

Commit

Permalink
Merge pull request #604 from python-rope/fix-test-isolation
Browse files Browse the repository at this point in the history
Fix test that sometimes leaves files behind in the current working directory
  • Loading branch information
lieryan committed Dec 16, 2022
2 parents 85301a1 + 637bb9e commit 0eb895b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# **Upcoming release**

- #604 Fix test that sometimes leaves files behind in the current working directory (@lieryan)

# Release 1.6.0

Expand Down
26 changes: 14 additions & 12 deletions ropetest/projecttest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path
import pathlib
import tempfile
import unittest
from textwrap import dedent
Expand Down Expand Up @@ -67,22 +68,23 @@ def test_creating_files_that_already_exist(self):
self.project.root.create_file(self.sample_file)

def test_making_root_folder_if_it_does_not_exist(self):
project = Project("sampleproject2")
try:
self.assertTrue(
os.path.exists("sampleproject2") and os.path.isdir("sampleproject2")
)
finally:
testutils.remove_project(project)
with tempfile.TemporaryDirectory(dir=testutils.RUN_TMP_DIR) as tmpdir:
project_root = pathlib.Path(tmpdir) / "sampleproject2"
assert not project_root.exists()

project = Project(project_root)

assert project_root.exists()
assert project_root.is_dir()

def test_failure_when_project_root_exists_and_is_a_file(self):
project_root = "sampleproject2"
try:
open(project_root, "w").close()
with tempfile.TemporaryDirectory(dir=testutils.RUN_TMP_DIR) as tmpdir:
project_root = pathlib.Path(tmpdir) / "sampleproject2"
project_root.touch()
assert project_root.exists() and project_root.is_file()

with self.assertRaises(RopeError):
Project(project_root)
finally:
testutils.remove_recursively(project_root)

def test_creating_folders(self):
folderName = "SampleFolder"
Expand Down

0 comments on commit 0eb895b

Please sign in to comment.