Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6db029cf
Commit
6db029cf
authored
Feb 05, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix unittest conversion breakage.
parent
56db6d43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
29 deletions
+30
-29
Lib/test/test_funcattrs.py
Lib/test/test_funcattrs.py
+30
-29
No files found.
Lib/test/test_funcattrs.py
View file @
6db029cf
...
...
@@ -2,16 +2,6 @@ from test import test_support
import
types
import
unittest
def
cannot_set_attr
(
obj
,
name
,
value
,
exceptions
):
# This method is not called as a test (name doesn't start with 'test'),
# but may be used by other tests.
try
:
setattr
(
obj
,
name
,
value
)
except
exceptions
:
pass
else
:
self
.
fail
(
"shouldn't be able to set %s to %r"
%
(
name
,
value
))
try
:
delattr
(
obj
,
name
)
except
exceptions
:
pass
else
:
self
.
fail
(
"shouldn't be able to del %s"
%
name
)
class
FuncAttrsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
F
:
...
...
@@ -23,6 +13,17 @@ class FuncAttrsTest(unittest.TestCase):
self
.
fi
=
F
()
self
.
b
=
b
def
cannot_set_attr
(
self
,
obj
,
name
,
value
,
exceptions
):
# This method is not called as a test (name doesn't start with 'test'),
# but may be used by other tests.
try
:
setattr
(
obj
,
name
,
value
)
except
exceptions
:
pass
else
:
self
.
fail
(
"shouldn't be able to set %s to %r"
%
(
name
,
value
))
try
:
delattr
(
obj
,
name
)
except
exceptions
:
pass
else
:
self
.
fail
(
"shouldn't be able to del %s"
%
name
)
class
FunctionPropertiesTest
(
FuncAttrsTest
):
# Include the external setUp method that is common to all tests
def
test_module
(
self
):
...
...
@@ -56,7 +57,7 @@ class FunctionPropertiesTest(FuncAttrsTest):
def
test_func_globals
(
self
):
self
.
assertEqual
(
self
.
b
.
func_globals
,
globals
())
cannot_set_attr
(
self
.
b
,
'func_globals'
,
2
,
TypeError
)
self
.
cannot_set_attr
(
self
.
b
,
'func_globals'
,
2
,
TypeError
)
def
test_func_name
(
self
):
self
.
assertEqual
(
self
.
b
.
__name__
,
'b'
)
...
...
@@ -68,8 +69,8 @@ class FunctionPropertiesTest(FuncAttrsTest):
self
.
assertEqual
(
self
.
b
.
__name__
,
'd'
)
self
.
assertEqual
(
self
.
b
.
func_name
,
'd'
)
# __name__ and func_name must be a string
cannot_set_attr
(
self
.
b
,
'__name__'
,
7
,
TypeError
)
cannot_set_attr
(
self
.
b
,
'func_name'
,
7
,
TypeError
)
self
.
cannot_set_attr
(
self
.
b
,
'__name__'
,
7
,
TypeError
)
self
.
cannot_set_attr
(
self
.
b
,
'func_name'
,
7
,
TypeError
)
# __name__ must be available when in restricted mode. Exec will raise
# AttributeError if __name__ is not available on f.
s
=
"""def f(): pass
\
n
f.__name__"""
...
...
@@ -77,8 +78,8 @@ class FunctionPropertiesTest(FuncAttrsTest):
# Test on methods, too
self
.
assertEqual
(
self
.
f
.
a
.
__name__
,
'a'
)
self
.
assertEqual
(
self
.
fi
.
a
.
__name__
,
'a'
)
cannot_set_attr
(
self
.
f
.
a
,
"__name__"
,
'a'
,
AttributeError
)
cannot_set_attr
(
self
.
fi
.
a
,
"__name__"
,
'a'
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
f
.
a
,
"__name__"
,
'a'
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
fi
.
a
,
"__name__"
,
'a'
,
AttributeError
)
def
test_func_code
(
self
):
num_one
,
num_two
=
7
,
8
...
...
@@ -135,21 +136,21 @@ class ImplicitReferencesTest(FuncAttrsTest):
def
test_im_class
(
self
):
self
.
assertEqual
(
self
.
f
.
a
.
im_class
,
self
.
f
)
self
.
assertEqual
(
self
.
fi
.
a
.
im_class
,
self
.
f
)
cannot_set_attr
(
self
.
f
.
a
,
"im_class"
,
self
.
f
,
TypeError
)
cannot_set_attr
(
self
.
fi
.
a
,
"im_class"
,
self
.
f
,
TypeError
)
self
.
cannot_set_attr
(
self
.
f
.
a
,
"im_class"
,
self
.
f
,
TypeError
)
self
.
cannot_set_attr
(
self
.
fi
.
a
,
"im_class"
,
self
.
f
,
TypeError
)
def
test_im_func
(
self
):
self
.
f
.
b
=
self
.
b
self
.
assertEqual
(
self
.
f
.
b
.
im_func
,
self
.
b
)
self
.
assertEqual
(
self
.
fi
.
b
.
im_func
,
self
.
b
)
cannot_set_attr
(
self
.
f
.
b
,
"im_func"
,
self
.
b
,
TypeError
)
cannot_set_attr
(
self
.
fi
.
b
,
"im_func"
,
self
.
b
,
TypeError
)
self
.
cannot_set_attr
(
self
.
f
.
b
,
"im_func"
,
self
.
b
,
TypeError
)
self
.
cannot_set_attr
(
self
.
fi
.
b
,
"im_func"
,
self
.
b
,
TypeError
)
def
test_im_self
(
self
):
self
.
assertEqual
(
self
.
f
.
a
.
im_self
,
None
)
self
.
assertEqual
(
self
.
fi
.
a
.
im_self
,
self
.
fi
)
cannot_set_attr
(
self
.
f
.
a
,
"im_self"
,
None
,
TypeError
)
cannot_set_attr
(
self
.
fi
.
a
,
"im_self"
,
self
.
fi
,
TypeError
)
self
.
cannot_set_attr
(
self
.
f
.
a
,
"im_self"
,
None
,
TypeError
)
self
.
cannot_set_attr
(
self
.
fi
.
a
,
"im_self"
,
self
.
fi
,
TypeError
)
def
test_im_func_non_method
(
self
):
# Behavior should be the same when a method is added via an attr
...
...
@@ -162,8 +163,8 @@ class ImplicitReferencesTest(FuncAttrsTest):
except
AttributeError
:
pass
else
:
self
.
fail
(
"using unknown attributes should raise AttributeError"
)
# Test assignment and deletion
cannot_set_attr
(
self
.
f
.
id
,
'unknown_attr'
,
2
,
AttributeError
)
cannot_set_attr
(
self
.
fi
.
id
,
'unknown_attr'
,
2
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
f
.
id
,
'unknown_attr'
,
2
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
fi
.
id
,
'unknown_attr'
,
2
,
AttributeError
)
def
test_implicit_method_properties
(
self
):
self
.
f
.
a
.
im_func
.
known_attr
=
7
...
...
@@ -202,12 +203,12 @@ class ArbitraryFunctionAttrTest(FuncAttrsTest):
class
FunctionDictsTest
(
FuncAttrsTest
):
def
test_setting_dict_to_invalid
(
self
):
cannot_set_attr
(
self
.
b
,
'__dict__'
,
None
,
TypeError
)
cannot_set_attr
(
self
.
b
,
'func_dict'
,
None
,
TypeError
)
self
.
cannot_set_attr
(
self
.
b
,
'__dict__'
,
None
,
TypeError
)
self
.
cannot_set_attr
(
self
.
b
,
'func_dict'
,
None
,
TypeError
)
from
UserDict
import
UserDict
d
=
UserDict
({
'known_attr'
:
7
})
cannot_set_attr
(
self
.
f
.
a
.
im_func
,
'__dict__'
,
d
,
TypeError
)
cannot_set_attr
(
self
.
fi
.
a
.
im_func
,
'__dict__'
,
d
,
TypeError
)
self
.
cannot_set_attr
(
self
.
f
.
a
.
im_func
,
'__dict__'
,
d
,
TypeError
)
self
.
cannot_set_attr
(
self
.
fi
.
a
.
im_func
,
'__dict__'
,
d
,
TypeError
)
def
test_setting_dict_to_valid
(
self
):
d
=
{
'known_attr'
:
7
}
...
...
@@ -259,8 +260,8 @@ class FunctionDocstringTest(FuncAttrsTest):
self
.
assertEqual
(
self
.
b
.
func_doc
,
docstr
)
self
.
assertEqual
(
self
.
f
.
a
.
__doc__
,
docstr
)
self
.
assertEqual
(
self
.
fi
.
a
.
__doc__
,
docstr
)
cannot_set_attr
(
self
.
f
.
a
,
"__doc__"
,
docstr
,
AttributeError
)
cannot_set_attr
(
self
.
fi
.
a
,
"__doc__"
,
docstr
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
f
.
a
,
"__doc__"
,
docstr
,
AttributeError
)
self
.
cannot_set_attr
(
self
.
fi
.
a
,
"__doc__"
,
docstr
,
AttributeError
)
def
test_delete_docstring
(
self
):
self
.
b
.
__doc__
=
"The docstring"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment