Skip to content

Commit

Permalink
Import 'mock' module from 'unittest' library (sonic-net#1415)
Browse files Browse the repository at this point in the history
As of Python 3, `mock` is part of `unittest` in the Python standard library. Since sonic-utilities is now Python 3-only, we should import it this way everywhere.
  • Loading branch information
jleveque authored Feb 10, 2021
1 parent a02190b commit 78968a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/config_dpb_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os
from imp import load_source
from unittest import mock

import mock
import pytest
from click.testing import CliRunner
from utilities_common.db import Db
Expand Down
9 changes: 4 additions & 5 deletions tests/config_mgmt_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import imp
import os
import sys
from unittest import mock, TestCase

# import file under test i.e. config_mgmt.py
imp.load_source('config_mgmt', \
os.path.join(os.path.dirname(__file__), '..', 'config', 'config_mgmt.py'))
import config_mgmt

from unittest import TestCase
from mock import MagicMock, call
from json import dump
from copy import deepcopy

Expand Down Expand Up @@ -108,8 +107,8 @@ def config_mgmt_dpb(self, curConfig):
self.writeJson(curConfig, config_mgmt.CONFIG_DB_JSON_FILE)
cmdpb = config_mgmt.ConfigMgmtDPB(source=config_mgmt.CONFIG_DB_JSON_FILE)
# mock funcs
cmdpb.writeConfigDB = MagicMock(return_value=True)
cmdpb._verifyAsicDB = MagicMock(return_value=True)
cmdpb.writeConfigDB = mock.MagicMock(return_value=True)
cmdpb._verifyAsicDB = mock.MagicMock(return_value=True)
from .mock_tables import dbconnector
return cmdpb

Expand Down Expand Up @@ -218,7 +217,7 @@ def checkResult(self, cmdpb, delConfig, addConfig):
Return:
void
'''
calls = [call(delConfig), call(addConfig)]
calls = [mock.call(delConfig), mock.call(addConfig)]
assert cmdpb.writeConfigDB.call_count == 2
cmdpb.writeConfigDB.assert_has_calls(calls, any_order=False)
return
Expand Down
4 changes: 3 additions & 1 deletion tests/reboot_cause_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import sys
import textwrap
import mock
from unittest import mock

from click.testing import CliRunner

from .mock_tables import dbconnector

test_path = os.path.dirname(os.path.abspath(__file__))
Expand Down

0 comments on commit 78968a1

Please sign in to comment.