Skip to content

Commit

Permalink
Merge pull request #190 from google/demox
Browse files Browse the repository at this point in the history
test: Fixing errors
  • Loading branch information
jaqx0r authored May 27, 2023
2 parents 2570ba0 + 5c2953b commit 14a5507
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
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

0 comments on commit 14a5507

Please sign in to comment.