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
68beef66
Kaydet (Commit)
68beef66
authored
Şub 28, 2010
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Pep8ify test names in the examples.
üst
78fd521f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
unittest.rst
Doc/library/unittest.rst
+17
-17
No files found.
Doc/library/unittest.rst
Dosyayı görüntüle @
68beef66
...
...
@@ -165,9 +165,9 @@ command line. For example, the last two lines may be replaced with::
Running the revised script from the interpreter or another script produces the
following output::
testchoice (__main__.TestSequenceFunctions) ... ok
testsample (__main__.TestSequenceFunctions) ... ok
testshuffle (__main__.TestSequenceFunctions) ... ok
test
_
choice (__main__.TestSequenceFunctions) ... ok
test
_
sample (__main__.TestSequenceFunctions) ... ok
test
_
shuffle (__main__.TestSequenceFunctions) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.110s
...
...
@@ -351,32 +351,32 @@ mechanism::
self.widget.dispose()
self.widget = None
def test
DefaultS
ize(self):
def test
_default_s
ize(self):
self.assertEqual(self.widget.size(), (50,50),
'incorrect default size')
def test
R
esize(self):
def test
_r
esize(self):
self.widget.resize(100,150)
self.assertEqual(self.widget.size(), (100,150),
'wrong size after resize')
Here we have not provided a :meth:`~TestCase.runTest` method, but have instead
provided two different test methods. Class instances will now each run one of
the :meth:`test\*` methods, with ``self.widget`` created and destroyed
the :meth:`test
_
\*` methods, with ``self.widget`` created and destroyed
separately for each instance. When creating an instance we must specify the
test method it is to run. We do this by passing the method name in the
constructor::
defaultSizeTestCase = WidgetTestCase('test
DefaultS
ize')
resizeTestCase = WidgetTestCase('test
R
esize')
defaultSizeTestCase = WidgetTestCase('test
_default_s
ize')
resizeTestCase = WidgetTestCase('test
_r
esize')
Test case instances are grouped together according to the features they test.
:mod:`unittest` provides a mechanism for this: the :dfn:`test suite`,
represented by :mod:`unittest`'s :class:`TestSuite` class::
widgetTestSuite = unittest.TestSuite()
widgetTestSuite.addTest(WidgetTestCase('test
DefaultS
ize'))
widgetTestSuite.addTest(WidgetTestCase('test
R
esize'))
widgetTestSuite.addTest(WidgetTestCase('test
_default_s
ize'))
widgetTestSuite.addTest(WidgetTestCase('test
_r
esize'))
For the ease of running tests, as we will see later, it is a good idea to
provide in each test module a callable object that returns a pre-built test
...
...
@@ -384,14 +384,14 @@ suite::
def suite():
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase('test
DefaultS
ize'))
suite.addTest(WidgetTestCase('test
R
esize'))
suite.addTest(WidgetTestCase('test
_default_s
ize'))
suite.addTest(WidgetTestCase('test
_r
esize'))
return suite
or even::
def suite():
tests = ['test
DefaultSize', 'testR
esize']
tests = ['test
_default_size', 'test_r
esize']
return unittest.TestSuite(map(WidgetTestCase, tests))
...
...
@@ -402,8 +402,8 @@ populating it with individual tests. For example, ::
suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)
will create a test suite that will run ``WidgetTestCase.test
DefaultS
ize()`` and
``WidgetTestCase.test
R
esize``. :class:`TestLoader` uses the ``'test'`` method
will create a test suite that will run ``WidgetTestCase.test
_default_s
ize()`` and
``WidgetTestCase.test
_r
esize``. :class:`TestLoader` uses the ``'test'`` method
name prefix to identify test methods automatically.
Note that the order in which the various test cases will be run is determined by
...
...
@@ -610,8 +610,8 @@ Test cases
def suite():
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase('test
DefaultS
ize'))
suite.addTest(WidgetTestCase('test
R
esize'))
suite.addTest(WidgetTestCase('test
_default_s
ize'))
suite.addTest(WidgetTestCase('test
_r
esize'))
return suite
Here, we create two instances of :class:`WidgetTestCase`, each of which runs a
...
...
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