Skip to content

Commit 8ed3c58

Browse files
authored
Merge pull request #110 from TotallyNotRobots/gonzobot+replace-mock
Switch mock -> unittest.mock
2 parents 9e23933 + 236eb30 commit 8ed3c58

39 files changed

+105
-66
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Refactor tests to remove dependency on mock library
810

911
## [1.3.0] 2020-03-17
1012
### Added

tests/core_tests/test_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import textwrap
2+
from unittest.mock import patch
23

34
import pytest
4-
from mock import patch
55

66
from cloudbot import config
77

tests/core_tests/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
2-
3-
from mock import MagicMock, patch
2+
from unittest.mock import MagicMock, patch
43

54
from cloudbot.client import Client
65

tests/core_tests/test_plugin_hooks.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
from collections import OrderedDict
99
from numbers import Number
1010
from pathlib import Path
11+
from unittest.mock import patch
1112

1213
import pytest
13-
from mock import patch
1414

1515
import cloudbot.bot
1616
from cloudbot.event import (
17-
CapEvent, CommandEvent, Event, EventType, IrcOutEvent, PostHookEvent, RegexEvent,
17+
CapEvent,
18+
CommandEvent,
19+
Event,
20+
EventType,
21+
IrcOutEvent,
22+
PostHookEvent,
23+
RegexEvent,
1824
)
1925
from cloudbot.hook import Action
2026
from cloudbot.plugin import Plugin

tests/core_tests/test_plugin_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import asyncio
22
import itertools
33
from pathlib import Path
4+
from unittest.mock import MagicMock, patch
45

56
import pytest
6-
from mock import MagicMock, patch
77

88
from cloudbot import hook
99
from cloudbot.plugin import PluginManager

tests/core_tests/util_tests/test_colors.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import mock
1+
from unittest.mock import patch
2+
23
import pytest
34

4-
from cloudbot.util.colors import parse, strip, get_available_colours, get_available_formats, get_color, get_format, \
5-
_convert, strip_irc, strip_all, IRC_COLOUR_DICT
5+
from cloudbot.util.colors import (
6+
IRC_COLOUR_DICT,
7+
_convert,
8+
get_available_colours,
9+
get_available_formats,
10+
get_color,
11+
get_format,
12+
parse,
13+
strip,
14+
strip_all,
15+
strip_irc,
16+
)
617

718
test_input = "The quick $(brown, red)brown$(clear) fox$(fake) jumps over the $(bold)lazy dog$(clear)."
819

@@ -53,7 +64,7 @@ def test_get_random_color():
5364
assert get_color("random") in ["\x03" + i for i in IRC_COLOUR_DICT.values()]
5465
assert get_color("random", return_formatted=False) in list(IRC_COLOUR_DICT.values())
5566

56-
with mock.patch(
67+
with patch(
5768
'cloudbot.util.colors.randint',
5869
return_value=4 # chosen by fair dice roll, guranteed to be random.
5970
):

tests/core_tests/util_tests/test_filesize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cloudbot.util.filesize as fs
2-
from cloudbot.util.filesize import size, si, verbose
2+
from cloudbot.util.filesize import si, size, verbose
33

44

55
def test_size():

tests/core_tests/util_tests/test_formatting.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22

33
import pytest
44

5-
from cloudbot.util.formatting import munge, dict_format, strip_colors, truncate, truncate_str, \
6-
strip_html, multi_replace, multiword_replace, truncate_words, smart_split, get_text_list, ireplace, chunk_str, \
7-
pluralize_suffix, pluralize_auto, gen_markdown_table
5+
from cloudbot.util.formatting import (
6+
chunk_str,
7+
dict_format,
8+
gen_markdown_table,
9+
get_text_list,
10+
ireplace,
11+
multi_replace,
12+
multiword_replace,
13+
munge,
14+
pluralize_auto,
15+
pluralize_suffix,
16+
smart_split,
17+
strip_colors,
18+
strip_html,
19+
truncate,
20+
truncate_str,
21+
truncate_words,
22+
)
823

924
test_munge_input = "The quick brown fox jumps over the lazy dog"
1025
test_munge_count = 3

tests/core_tests/util_tests/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mock import patch
1+
from unittest.mock import patch
22

33

44
def test_get_soup():

tests/core_tests/util_tests/test_tokenbucket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
2+
from unittest.mock import patch
23

34
import pytest
4-
from mock import patch
55

66
from cloudbot.util import tokenbucket
77

0 commit comments

Comments
 (0)