Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fixing errors #190

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions nss_cache/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def setUp(self):
dev_null = io.StringIO()
self.stdout = sys.stdout
sys.stdout = dev_null
self.srcdir = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..'))
self.conf_filename = os.path.join(self.srcdir, 'nsscache.conf')

def tearDown(self):
sys.stdout = self.stdout
Expand Down Expand Up @@ -119,16 +122,16 @@ def testHelpCommandOutput(self):
self.assertTrue(
stdout_buffer.getvalue().find('nsscache synchronises') >= 0)

@unittest.skip('cant pass unless theres a valid config')
def testRunBadArgsPrintsGlobalHelp(self):
# trap stdout into a StringIO
stdout_buffer = io.StringIO()
old_stdout = sys.stdout
sys.stdout = stdout_buffer
# verify bad arguments calls help
return_code = app.NssCacheApp().Run(['blarg'], {})
return_code = app.NssCacheApp().Run(
['blarg'], {'NSSCACHE_CONFIG': self.conf_filename})
sys.stdout = old_stdout
assert return_code == 1
assert return_code == 70 # EX_SOFTWARE
assert stdout_buffer.getvalue().find('enable debugging') >= 0


Expand Down
6 changes: 5 additions & 1 deletion nss_cache/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ class TestClassMethods(unittest.TestCase):
def setUp(self):
# create a directory with a writeable copy of nsscache.conf in it
self.workdir = tempfile.mkdtemp()
# nsscache.conf is in the parent dir of this test.
self.srcdir = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..'))
conf_filename = 'nsscache.conf'
self.conf_filename = os.path.join(self.workdir, conf_filename)
shutil.copy(conf_filename, self.conf_filename)
shutil.copy(os.path.join(self.srcdir, conf_filename),
self.conf_filename)
os.chmod(self.conf_filename, 0o640)

# prepare a config object with this config
Expand Down
10 changes: 4 additions & 6 deletions nss_cache/lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,14 @@ def testLockCreatesPidfiles(self):

# Note that testing when self._file is not None is covered below.

def testLockLocksWithFcntl(self):
@mock.patch('fcntl.lockf')
def testLockLocksWithFcntl(self, lockf):
locker = lock.PidFile(pid='PID')

with mock.patch.object(
locker, '_file') as f, mock.patch('fcntl.lockf') as lockf:

with mock.patch.object(locker, '_file') as f:
locker.Lock()
self.assertTrue(locker._locked)
lockf.assert_called_once_with(locker._file,
fcntl.LOCK_EX | fcntl.LOCK_NB)
lockf.assert_called_once_with(f, fcntl.LOCK_EX | fcntl.LOCK_NB)

def testLockStoresPid(self):
locker = lock.PidFile(filename=self.filename, pid='PID')
Expand Down