Skip to content

Commit

Permalink
Use a temporary file for the application_preferences_filename (#338)
Browse files Browse the repository at this point in the history
Closes #337 

This PR ensures that tests of `ScopedPreferences` use a temporary file
for the application preferences scope.
  • Loading branch information
mdickinson authored Jul 4, 2024
1 parent e2d439a commit c8c3224
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion apptools/preferences/tests/test_preferences_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ class AcmeUIPreferencesHelper(PreferencesHelper):
def test_scoped_preferences(self):
""" scoped preferences """

p = set_default_preferences(ScopedPreferences())
p = set_default_preferences(
ScopedPreferences(application_preferences_filename=self.tmpfile)
)

# Set a preference value in the default scope.
p.set("default/acme.ui.bgcolor", "blue")
Expand Down
12 changes: 8 additions & 4 deletions apptools/preferences/tests/test_scoped_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ class ScopedPreferencesTestCase(PreferencesTestCase):
def setUp(self):
""" Prepares the test fixture before each test method is called. """

self.preferences = ScopedPreferences()
# A temporary directory that can safely be written to.
self.tmpdir = tempfile.mkdtemp()

self.preferences = ScopedPreferences(
application_preferences_filename=os.path.join(
self.tmpdir, "preferences.ini"
)
)

# The filename of the example preferences file.
self.example = os.fspath(files(PKG) / "example.ini")

# A temporary directory that can safely be written to.
self.tmpdir = tempfile.mkdtemp()

def tearDown(self):
""" Called immediately after each test method has been called. """

Expand Down

0 comments on commit c8c3224

Please sign in to comment.