Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8ada1774
Kaydet (Commit)
8ada1774
authored
Şub 05, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix unittest conversion breakage.
üst
212861c5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
29 deletions
+30
-29
test_funcattrs.py
Lib/test/test_funcattrs.py
+30
-29
No files found.
Lib/test/test_funcattrs.py
Dosyayı görüntüle @
8ada1774
...
...
@@ -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