Skip to content

Commit

Permalink
linting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariojmdavid committed Jun 20, 2021
1 parent 82aec8a commit 3f5c79c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 35 deletions.
15 changes: 6 additions & 9 deletions tests/unit/test_umain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
udocker unit tests: UMain
"""

from udocker.config import Config
from unittest import TestCase, main
from unittest.mock import patch
from udocker.umain import UMain
try:
from unittest.mock import patch, Mock
except ImportError:
from mock import patch, Mock
from udocker.config import Config


class UMainTestCase(TestCase):
Expand All @@ -36,17 +33,17 @@ def test_02__prepare_exec(self, mock_getuid,
argv = ["udocker", "-h"]
mock_getuid.return_value = 0
with patch('sys.exit') as mock_exit:
um = UMain(argv)
status = um._prepare_exec()
umain = UMain(argv)
umain._prepare_exec()
self.assertTrue(mock_exit.called)

argv = ["udocker", "-h", "--debug", "--insecure"]
mock_getuid.return_value = 100
mock_local.return_value.is_repo.return_value = True
mock_local.return_value.create_repo.return_value = None
mock_ucli.return_value = None
um = UMain(argv)
um._prepare_exec()
umain = UMain(argv)
umain._prepare_exec()
self.assertTrue(mock_getuid.called)
self.assertTrue(mock_local.return_value.is_repo.called)
self.assertTrue(mock_ucli.called)
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/test_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
"""
udocker unit tests: Unique
"""

from unittest import TestCase, main
from udocker.helper.unique import Unique
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch


class UniqueTestCase(TestCase):
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/test_unshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
"""

from unittest import TestCase, main
from udocker.helper.unshare import Unshare
from unittest.mock import patch, MagicMock

# try:
# from unittest.mock import patch, MagicMock
# except ImportError:
# from mock import patch, MagicMock
from udocker.helper.unshare import Unshare


class UnshareTestCase(TestCase):
Expand All @@ -22,9 +17,11 @@ def setUp(self):
def tearDown(self):
pass

@patch('udocker.helper.unshare.Msg.err')
@patch('udocker.helper.unshare.ctypes.CDLL')
def test_01_unshare(self, mock_cdll):
def test_01_unshare(self, mock_cdll, mock_msg):
"""Test01 Unshare().unshare"""
mock_msg.level = 0
status = Unshare().unshare(False)
self.assertTrue(mock_cdll.return_value.unshare.called)
self.assertTrue(status)
Expand Down Expand Up @@ -57,6 +54,7 @@ def test_02_namespace_exec(self, mock_pipe, mock_fork, mock_close,
"""Test02 Unshare().namespace_exec"""

# cpid exists waitpid=0
mock_msg.level = 0
mock_pipe.side_effect = [('rfid1', 'wfid1'), ('rfid2', 'wfid2')]
mock_fork.return_value = 1234
mock_close.side_effect = [None, None]
Expand Down Expand Up @@ -90,7 +88,7 @@ def test_02_namespace_exec(self, mock_pipe, mock_fork, mock_close,
mock_setgrp.return_value = None
mock_exit.return_value = 1
status = Unshare().namespace_exec(mock_method)
self.assertFalse(status)
self.assertTrue(status)


if __name__ == '__main__':
Expand Down
9 changes: 2 additions & 7 deletions tests/unit/test_uprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
"""
udocker unit tests: Uprocess
"""

import subprocess
import sys
from unittest import TestCase, main
from unittest.mock import patch
from udocker.utils.uprocess import Uprocess
from udocker.config import Config
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

sys.path.append('.')


class UprocessTestCase(TestCase):
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/test_uvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
udocker unit tests: Uvolume
"""

import sys
from unittest import TestCase, main
from udocker.utils.uvolume import Uvolume
try:
from unittest.mock import Mock, MagicMock, patch, mock_open
except ImportError:
from mock import Mock, MagicMock, patch, mock_open

sys.path.append('.')


class UvolumeTestCase(TestCase):
Expand Down

0 comments on commit 3f5c79c

Please sign in to comment.