Skip to content

Commit

Permalink
tests: make use of the stdlib unittest.mock for python 3.3+
Browse files Browse the repository at this point in the history
Fixes: #339
  • Loading branch information
eli-schwartz committed Jul 5, 2024
1 parent 667bab0 commit dddd7b3
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# testing
pytest
mock
mock; python_version < 3.3
flexmock
parameterized
tox
Expand Down
6 changes: 6 additions & 0 deletions tests/support/mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

if sys.version_info > (3, 3):
from unittest.mock import *
else:
from mock import *
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock
from tests.support.mock import Mock

from tests.support.make_scripts import Scripts
from tests.support.make_scripts import script_path_without_base_dir_for
Expand Down
6 changes: 2 additions & 4 deletions tests/test_dev_tools/test_make_scripts/test_make_script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from textwrap import dedent

import mock
from mock import Mock
from tests.support import mock
from tests.support.mock import Mock

from tests.support.make_scripts import Scripts
from tests.support.make_scripts import script_path_for
Expand Down Expand Up @@ -43,5 +43,3 @@ def test_the_script_should_call_the_right_function_from_the_right_module(self):
assert expected == contents, ("Expected:\n---\n%s---\n"
"Actual :\n---\n%s---\n"
% (expected, contents))


3 changes: 1 addition & 2 deletions tests/test_empty/cmd/test_empty_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from typing import cast

from mock import call
from tests.support.mock import Mock, call
from six import StringIO

from tests.support.fakes.stub_volume_of import StubVolumeOf
Expand All @@ -14,7 +14,6 @@
from trashcli.fstab.volume_listing import VolumesListing
from trashcli.lib.dir_reader import DirReader
from trashcli.trash_dirs_scanner import TopTrashDirRules
from mock import Mock

class TestTrashEmptyCmdFs(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_empty/cmd/test_empty_cmd_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest

import pytest
from mock import Mock
from tests.support.mock import Mock
from six import StringIO

from tests.support.fakes.stub_volume_of import StubVolumeOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import unittest

from mock import Mock
from tests.support.mock import Mock
from six import StringIO

from tests.support.fakes.stub_volume_of import StubVolumeOf
Expand Down
2 changes: 1 addition & 1 deletion tests/test_empty/components/test_clock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call
from trashcli.empty.clock import Clock


Expand Down
2 changes: 1 addition & 1 deletion tests/test_empty/components/test_guard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call
from trashcli.empty.guard import Guard, UserIntention


Expand Down
2 changes: 1 addition & 1 deletion tests/test_empty/components/test_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call

from trashcli.empty.user import User
from trashcli.lib.my_input import HardCodedInput
Expand Down
2 changes: 1 addition & 1 deletion tests/test_put/components/test_trash_directories_finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock
from tests.support.mock import Mock

from trashcli.put.core.candidate import Candidate
from trashcli.put.core.check_type import NoCheck, TopTrashDirCheck
Expand Down
2 changes: 1 addition & 1 deletion tests/test_put/components/test_trash_put_reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import Mock
from tests.support.mock import Mock
from six import StringIO
from trashcli.put.describer import Describer

Expand Down
2 changes: 1 addition & 1 deletion tests/test_restore/cmd/test_listing_in_restore_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock
from tests.support.mock import Mock
from six import StringIO

from trashcli.restore.file_system import FakeReadCwd
Expand Down
2 changes: 1 addition & 1 deletion tests/test_restore/cmd/test_restore2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call

from tests.support.restore.fake_restore_fs import FakeRestoreFs
from tests.support.restore.restore_user import RestoreUser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import unittest

from mock import Mock
from tests.support.mock import Mock
from six import StringIO

from tests.support.files import make_empty_file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call

from trashcli.lib.my_input import HardCodedInput
from trashcli.restore.output_event import Quit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

import pytest
from mock import Mock, call
from tests.support.mock import Mock, call

from tests.support.fakes.stub_volume_of import StubVolumeOf
from trashcli.restore.trash_directories import TrashDirectories2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import unittest

from mock import Mock
from tests.support.mock import Mock

from tests.support.files import make_file, require_empty_dir
from tests.support.dirs.remove_dir_if_exists import remove_dir_if_exists
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rm/cmd/test_trash_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from six import StringIO

from mock import Mock
from tests.support.mock import Mock

from tests.support.asserts import assert_starts_with
from trashcli.rm.rm_cmd import RmCmd
Expand Down
2 changes: 1 addition & 1 deletion tests/test_trashcli_lib/test_parsing_trashinfo_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from datetime import datetime

from mock import MagicMock
from tests.support.mock import MagicMock

from trashcli.parse_trashinfo.parse_path import parse_path
from trashcli.parse_trashinfo.parse_trashinfo import ParseTrashInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock, call
from tests.support.mock import Mock, call
from trashcli.trash_dirs_scanner import (
TopTrashDirRules,
top_trash_dir_does_not_exist,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mock import Mock
from tests.support.mock import Mock

from trashcli.fstab.volume_listing import VolumesListing
from trashcli.lib.dir_checker import DirChecker
Expand Down

0 comments on commit dddd7b3

Please sign in to comment.