Skip to content

Commit

Permalink
fix unit tests: path to biprime default dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mvesin committed Mar 9, 2023
1 parent 07fd662 commit d133160
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/test_secagg_manager_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import copy
import os

import inspect

from fedbiomed.common.constants import BiprimeType
from fedbiomed.common.exceptions import FedbiomedSecaggError
from fedbiomed.common.secagg_manager import SecaggServkeyManager, SecaggBiprimeManager
Expand Down Expand Up @@ -78,6 +80,14 @@ def setUp(self):
self.patcher_db.start()
self.patcher_query.start()

self.biprime_dir = os.path.join(
os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
),
"test-data",
"default_biprimes"
)

def tearDown(self) -> None:
self.patcher_query.stop()
self.patcher_db.stop()
Expand Down Expand Up @@ -355,10 +365,9 @@ def test_secagg_manager_08_update_default_biprimes_ok(self):
# prepare
bpm = SecaggBiprimeManager('/path/to/dummy/file')
bpm._table.insert({'secagg_id': 'ANOTHER'})
biprime_dir = './test-data/default_biprimes'

# test
bpm.update_default_biprimes(True, biprime_dir)
bpm.update_default_biprimes(True, self.biprime_dir)

# check
#
Expand All @@ -375,7 +384,7 @@ def test_secagg_manager_08_update_default_biprimes_ok(self):
bpm._query.secagg_id.exists = False

# test
bpm.update_default_biprimes(False, biprime_dir)
bpm.update_default_biprimes(False, self.biprime_dir)

# check
#
Expand All @@ -387,14 +396,13 @@ def test_secagg_manager_08_update_default_biprimes_fail(self):
"""
# prepare
bpm = SecaggBiprimeManager('/path/to/dummy/file')
biprime_dir = './test-data/default_biprimes'

for exception in ['bpm._table.exception_search', 'bpm._table.exception_remove', 'bpm._table.exception_upsert']:
exec(f'{exception} = True')

# test
with self.assertRaises(FedbiomedSecaggError):
bpm.update_default_biprimes(True, biprime_dir)
bpm.update_default_biprimes(True, self.biprime_dir)

# clean
exec(f'{exception} = False')
Expand All @@ -404,12 +412,11 @@ def test_secagg_manager_08_read_default_biprimes_fail(self):
"""
# prepare
bpm = SecaggBiprimeManager('/path/to/dummy/file')
biprime_dir = './test-data/default_biprimes'

with patch('builtins.open', return_value=Exception):
# test
with self.assertRaises(FedbiomedSecaggError):
bpm._read_default_biprimes(biprime_dir)
bpm._read_default_biprimes(self.biprime_dir)

for bad_json in [
None,
Expand All @@ -424,7 +431,7 @@ def test_secagg_manager_08_read_default_biprimes_fail(self):
with patch('json.load', return_value=bad_json):
# test
with self.assertRaises(FedbiomedSecaggError):
bpm._read_default_biprimes(biprime_dir)
bpm._read_default_biprimes(self.biprime_dir)


if __name__ == '__main__': # pragma: no cover
Expand Down

0 comments on commit d133160

Please sign in to comment.