Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101433

Fwd: python unit test framework sample code

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject Fwd: python unit test framework sample code
Date Sun, 10 Jan 2016 19:11:03 +0530
Lines 110
Message-ID <mailman.2.1452433272.3151.python-list@python.org> (permalink)
References <CACT3xuWoDMH5QJK1HUJxv2nNkpUcCk-OUawofpyKozE3cv-WKQ@mail.gmail.com> <n6k26f$grd$1@ger.gmane.org> <CACT3xuXWwwc_Z++eAmj9nFmF_jjkwQeUxj1Q8WGp9FovcH-L=Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de PlGjRIdSC5cWqXRM6syK1gsLjTpWARXfA1LvLQanw3+A==
Return-Path <ganesh1pal@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'overflow': 0.07; 'run,': 0.07; 'subject:code': 0.07; 'subject:test': 0.07; 'unittest': 0.07; 'python': 0.10; 'jan': 0.11; 'stack': 0.13; 'def': 0.13; 'subject:python': 0.14; 'skip:f 30': 0.15; 'thu,': 0.15; '(possible': 0.16; '2016': 0.16; '@classmethod': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:sample': 0.16; 'unittest,': 0.16; 'unittest2.': 0.16; 'refers': 0.18; 'skip:l 30': 0.18; 'version.': 0.18; 'tests': 0.18; '>>>': 0.20; 'to:name:python-list@python.org': 0.20; 'assuming': 0.22; 'trying': 0.22; 'header:In-Reply-To:1': 0.24; 'module': 0.25; '----------': 0.25; 'example': 0.26; 'skip:t 40': 0.27; 'message-id:@mail.gmail.com': 0.27; '2.6': 0.27; 'initial': 0.28; 'looks': 0.29; '(perhaps': 0.29; 'code': 0.30; 'class.': 0.30; 'error.': 0.31; 'date:': 0.31; 'skip:s 30': 0.31; 'skip:_ 10': 0.32; 'older': 0.32; 'run': 0.33; 'changed': 0.33; 'class': 0.33; "skip:' 20": 0.34; 'running': 0.34; 'received:google.com': 0.35; 'instance': 0.35; 'newer': 0.35; 'skip:s 60': 0.35; 'subject:': 0.35; 'unit': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'framework': 0.36; 'guidance': 0.36; 'to:addr:python-list': 0.36; 'forwarded': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'setting': 0.37; 'received:209': 0.38; 'test': 0.39; 'sure': 0.39; "didn't": 0.39; 'easily': 0.39; 'from:': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'skip:u 10': 0.61; 'body': 0.61; 'provide': 0.61; 'real': 0.62; 'here.': 0.62; 'more': 0.63; 'sample': 0.63; 'reply': 0.68; 'upgrading': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=EaMBzn/z2wMo2w5dr8xUS1TogSh3CemA/ma8A/6UOaM=; b=A3u2nk9buwGzTx91Q7p8Xx8DSN5Lbg/uTe7DytIhZ2zallpS/KiOqKzpvhdbkvQWqn XdUjt3l1U+7L8m5qSxnvR/aQaCAf142aAd/ofJKoLvQJw2kjuZnG1ET5E6UqP92p7B57 xpeCavAjg21qNeM/99z65Nz896GL8A0XPwtZo3i4I0JMLu1IDeQ6s3MJuwSAqmIXwEAm ycyYqNu/VveW/9ybdRKy4lMWeO7AEixlKf1kztvq/iNaaANopRvzi+o66LYIys6KMMZl IQZoO5pjWRHBVGPvQS7eNGtlTVGAzV/t52jN45YlnvX6UMz0UhB/GqtxE+rJch+Zgb6Z eYfQ==
X-Received by 10.112.149.202 with SMTP id uc10mr511522lbb.57.1452433263930; Sun, 10 Jan 2016 05:41:03 -0800 (PST)
In-Reply-To <CACT3xuXWwwc_Z++eAmj9nFmF_jjkwQeUxj1Q8WGp9FovcH-L=Q@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:101433

Show key headers only | View raw


Apologies,  looks like I did a reply instead of reply-all. So
forwarding this email , please provide guidance on the same

---------- Forwarded message ----------
From: Ganesh Pal <ganesh1pal@gmail.com>
Date: Thu, Jan 7, 2016 at 12:26 PM
Subject: Re: python unit test framework sample code
To: Terry Reedy <tjreedy@udel.edu>

> Unless you have a large program already in 2.6 and are just adding tests
> (perhaps so you can more easily upgrade someday), consider upgrading to a
> newer version.

Sure , but for now Iam limited to use 2.6 , hence I cant upgrade need
to work with 2.6

>>
>> class FileSystemTest(unittest2.TestCase):
>>      block_address = {}
>>      report = ""
>>
>>      @classmethod
>>      def setUpClass(cls):
>>          cls.FileSystemSetup()
>
>
> This is senseless.  Put the body of FileSystemSetup here.

I didn't understand  which line is senseless. I was trying to refer
this example on stack overflow
http://stackoverflow.com/questions/5938517/not-able-call-a-local-method-from-setupclass


class TestSystemPromotion(unittest2.TestCase):

  @classmethod
  def setUpClass(cls):
    cls.setup_test_data()


  @classmethod
  def setup_test_data(cls):
    ...

  def test_something(self):
    ...


class FileSystemTest(unittest2.TestCase):
    block_address = {}
    report = ""

    @classmethod
    def setUpClass(cls):
        cls.FileSystemSetup()

    @classmethod
    def FileSystemSetup(cls):
        """
        Initial setup before unittest is run
        """
        logging.info("SETUP.....Started !!!")

>>      def inode_corruption(self):
>>          """ test_01: inode  corruption """
>>          self.assertTrue(corrupt.run_query_tool(self.__class__.report,
>
>
> self.block_address['test_01']))
>
> Assuming that unittest2 is same as unittest, test methods must be called
> test_xyz.  So this is not run, hence no error.

Sorry  I have changed this from inode_corruption' to 'test_inode_corruption

>
>>      @classmethod
>>      def tearDownClass(cls):
>>          cls.tearDown()
>
>
> Ditto.  Put real body here.
>
>>      @classmethod
>>      def tearDown(cls):
>
>

> The above refers to functions you did not post.  For current unittest, it
> looks likes you should be using a setUpModule (possible tearDownModule)
> functions, but I don't know if those are available in the older unittest2.


we have tearDownClass and setUpClass in python 2.6 and under unittest2

>>> help(unittest2.TestCase.tearDownClass)
Help on method tearDownClass in module unittest2.case:

tearDownClass(cls) method of __builtin__.type instance
    Hook method for deconstructing the class fixture after running all
tests in the class.

>>> help(unittest2.TestCase.setUpClass)
Help on method setUpClass in module unittest2.case:

setUpClass(cls) method of __builtin__.type instance
    Hook method for setting up class fixture before running tests in the class.

Regards,
Ganesh

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Fwd: python unit test framework sample code Ganesh Pal <ganesh1pal@gmail.com> - 2016-01-10 19:11 +0530

csiph-web