From 3058d533326a8af0488fd014c55fce6e4c81845a Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Tue, 23 Apr 2019 23:43:30 -0700 Subject: [PATCH] Add test module for rbackup.system --- tests/test_system.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_system.py diff --git a/tests/test_system.py b/tests/test_system.py new file mode 100644 index 0000000..65d83d2 --- /dev/null +++ b/tests/test_system.py @@ -0,0 +1,43 @@ +""" +.. moduleauthor:: Eric Torres + +Tests for the rbackup.config module. +""" +import os +import unittest + +import rbackup.system as system + +# ========== Constants ========== +TESTING_PACKAGE = "rbackup" +TESTING_MODULE = f"{TESTING_PACKAGE}.system" + + +# ========== Tests ========== +class TestUmask(unittest.TestCase): + @staticmethod + def get_current_umask(): + """Obtain process umask, and then change it back for testing.""" + orig_umask = os.umask(0) + os.umask(orig_umask) + + return orig_umask + + def setUp(self): + self.test_umask = 0o0027 + self.orig_umask = self.get_current_umask() + + def test_original_umask_remains(self): + # noinspection PyBroadException + try: + with system.change_umask(self.test_umask): + self.assertEqual(self.get_current_umask(), self.test_umask) + + raise BaseException + except: + pass + + self.assertEqual(self.get_current_umask(), self.orig_umask) + + def tearDown(self): + os.umask(self.orig_umask)