From 75963643b178f9d72d3b6bb02d136d67c9cc6d3e Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Sat, 9 Jun 2012 17:31:59 +0100 Subject: Fix exception when calling reset_mock on a mock created with autospec --- Lib/unittest/mock.py | 3 +++ Lib/unittest/test/testmock/testhelpers.py | 7 +++++++ Lib/unittest/test/testmock/testmagicmethods.py | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 36be0fd..4ae3d16 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -510,6 +510,8 @@ class NonCallableMock(Base): self.method_calls = _CallList() for child in self._mock_children.values(): + if isinstance(child, _SpecState): + continue child.reset_mock() ret = self._mock_return_value @@ -664,6 +666,7 @@ class NonCallableMock(Base): # but not method calls _check_and_set_parent(self, value, None, name) setattr(type(self), name, value) + self._mock_children[name] = value elif name == '__class__': self._spec_class = value return diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index 7a7145e..8bfb293 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -355,6 +355,13 @@ class SpecSignatureTest(unittest.TestCase): self.assertEqual(mock(), 'foo') + def test_autospec_reset_mock(self): + m = create_autospec(int) + int(m) + m.reset_mock() + self.assertEqual(m.__int__.call_count, 0) + + def test_mocking_unbound_methods(self): class Foo(object): def foo(self, foo): diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py index bd52e25..2bcf088 100644 --- a/Lib/unittest/test/testmock/testmagicmethods.py +++ b/Lib/unittest/test/testmock/testmagicmethods.py @@ -345,6 +345,14 @@ class TestMockingMagicMethods(unittest.TestCase): self.assertEqual(mock[1][2][3], 3) + def test_magic_method_reset_mock(self): + mock = MagicMock() + str(mock) + self.assertTrue(mock.__str__.called) + mock.reset_mock() + self.assertFalse(mock.__str__.called) + + def test_dir(self): # overriding the default implementation for mock in Mock(), MagicMock(): -- cgit v0.12 > Tk is a free and open-source, cross-platform widget toolkit that provides a library of basic elements of GUI widgets for building a graphical user interface (GUI) in many programming languages.
summaryrefslogtreecommitdiffstats
path: root/unix/installManPage
blob: 16cf005888a30cad8236de714e3550b02b530d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

ZIP=:
while true; do
    case $1 in
        -s | --symlinks  )      S="-s ";;
        -z | --compress  )    ZIP=$2;  shift ;;
	-e | --extension )      Z=$2;  shift ;;
	-s | --suffix    ) SUFFIX=$2;  shift ;;
	*)  break ;;
    esac
    shift
done
if test "$#" != 2; then
    echo "Usage: installManPages <options> file dir"
    exit 1
fi

MANPAGE=$1
DIR=$2
test -z "$S" && S="$DIR/"

# Backslashes are trippled in the sed script, because it is in backticks
# which don't pass backslashes literally.
NAMES=`sed -n '
    /^\\.SH NAME/{    # Look for a line, that starts with .SH NAME
	s/^.*$//      # Delete the content of this line from the buffer
	n             # Read next line
	s/,\|\\\ //g  # Remove all commas
	s/ \\\-.*//   # Delete from \- to the end of line
	p             # print the result
	q
    }' $MANPAGE`

SECTION=`echo $MANPAGE | sed 's/.*\(.\)$/\1/'`
SRCDIR=`dirname $MANPAGE`
FIRST=""
for f in $NAMES; do
    f=$f.$SECTION$SUFFIX
    if test -z "$FIRST" ; then
	FIRST=$f
	rm -f $DIR/$FIRST $DIR/$FIRST.*
	sed -e "/man\.macros/r $SRCDIR/man.macros" -e "/man\.macros/d" \
	    $MANPAGE > $DIR/$FIRST
	chmod 444 $DIR/$FIRST
	$ZIP $DIR/$FIRST
    else
	rm -f $DIR/$f $DIR/$f.*
	ln $S$FIRST$Z $DIR/$f$Z
    fi
done