Skip to content

Commit

Permalink
Use pre-generated rcfile for user_settings tests
Browse files Browse the repository at this point in the history
This commit minimizes the test setup/teardown by adding a pre-
generated rcfile instead of writing a temp dir and an rcfile
on the fly, which should make the test slightly faster and maybe
more readable.
  • Loading branch information
lukpueh committed Nov 1, 2017
1 parent e023007 commit 728fd84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 4 additions & 0 deletions test/demo_files/.in_totorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
artifact_basepath=r/c/file
ARTIFACT_EXCLUDES=r:c:file
new_rc_setting=new rc setting
14 changes: 4 additions & 10 deletions test/test_user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,17 @@ class TestUserSettings(unittest.TestCase):
@classmethod
def setUpClass(self):
self.working_dir = os.getcwd()
self.test_dir = os.path.realpath(tempfile.mkdtemp())

# We use `demo_files` as test dir because it has an `.in_totorc`, which
# we is loaded (from CWD) in `user_settings.set_settings` related tests
self.test_dir = os.path.join(os.path.dirname(__file__), "demo_files")
os.chdir(self.test_dir)

# Backup settings
self.settings_backup = {}
for key in dir(in_toto.settings):
self.settings_backup[key] = getattr(in_toto.settings, key)

# Create an rc file and set some environment variables
with open(".in_totorc", "w") as fobj:
fobj.write(
"[settings]\n"
"artifact_basepath=r/c/file\n"
"ARTIFACT_EXCLUDES=r:c:file\n"
"new_rc_setting=new rc setting")

os.environ["IN_TOTO_ARTIFACT_EXCLUDES"] = "e:n:v"
os.environ["IN_TOTO_artifact_basepath"] = "e/n/v"
os.environ["IN_TOTO_NEW_ENV_SETTING"] = "new env setting"
Expand All @@ -59,7 +54,6 @@ def setUpClass(self):
@classmethod
def tearDownClass(self):
os.chdir(self.working_dir)
shutil.rmtree(self.test_dir)

# Restore settings, other unittests might depend on defaults
for key, val in self.settings_backup.iteritems():
Expand Down

0 comments on commit 728fd84

Please sign in to comment.