unittest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zunbeltz Izaola

    unittest

    Hi,

    I am using unittest for the first time. I have read chapter 7 of dive into
    pyhton (Unit Test). I have the following code

    from spacegroup import *
    import pygroups.misc.m atrix as matrix
    import unittest

    class KnowValues(unit test.TestCase):

    KnownRotationMa trices = [
    ((Rotational3Pa rt([[-1,0,0],[0,1,0],[0,0,-1]])),
    (1, -1, 2, matrix.vector([0,1,0])))
    ]

    def TestRotationalP artdeterminant( self):
    """ RotationalPart. determinant with known values."""
    for i in self.KnownRotat ionMatrices:
    det = i[0].determinant()
    self.assertEqua l(det,i[1][0])


    if __name__ == "__main__":
    unittest.main()

    but when i run this scrip i get the following output


    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s

    OK

    Why the test didn't run? any idea?

    TIA

    Zunbeltz
  • Skip Montanaro

    #2
    Re: unittest


    Zunbeltz> class KnowValues(unit test.TestCase):

    Zunbeltz> KnownRotationMa trices = [
    Zunbeltz> ((Rotational3Pa rt([[-1,0,0],[0,1,0],[0,0,-1]])),
    Zunbeltz> (1, -1, 2, matrix.vector([0,1,0])))
    Zunbeltz> ]

    Zunbeltz> def TestRotationalP artdeterminant( self):
    Zunbeltz> """ RotationalPart. determinant with known values."""
    Zunbeltz> for i in self.KnownRotat ionMatrices:
    Zunbeltz> det = i[0].determinant()
    Zunbeltz> self.assertEqua l(det,i[1][0])


    Zunbeltz> if __name__ == "__main__":
    Zunbeltz> unittest.main()

    Zunbeltz> but when i run this scrip i get the following output

    ...

    Try renaming your test case method "test_rotationa l_partdetermina nt".

    Skip


    Comment

    • Zunbeltz Izaola

      #3
      Re: unittest

      Tnaks, why is this so?

      zunbeltz

      Skip Montanaro <skip@pobox.com > writes:
      [color=blue]
      > Zunbeltz> class KnowValues(unit test.TestCase):
      >
      > Zunbeltz> KnownRotationMa trices = [
      > Zunbeltz> ((Rotational3Pa rt([[-1,0,0],[0,1,0],[0,0,-1]])),
      > Zunbeltz> (1, -1, 2, matrix.vector([0,1,0])))
      > Zunbeltz> ]
      >
      > Zunbeltz> def TestRotationalP artdeterminant( self):
      > Zunbeltz> """ RotationalPart. determinant with known values."""
      > Zunbeltz> for i in self.KnownRotat ionMatrices:
      > Zunbeltz> det = i[0].determinant()
      > Zunbeltz> self.assertEqua l(det,i[1][0])
      >
      >
      > Zunbeltz> if __name__ == "__main__":
      > Zunbeltz> unittest.main()
      >
      > Zunbeltz> but when i run this scrip i get the following output
      >
      > ...
      >
      > Try renaming your test case method "test_rotationa l_partdetermina nt".
      >
      > Skip[/color]

      Comment

      • Jeremy Fincher

        #4
        Re: unittest

        Change your method name to begin with "test" instead of "Test" and it should work.

        Jeremy

        Comment

        • David Goodger

          #5
          Re: unittest

          Zunbeltz Izaola wrote:[color=blue]
          > Tnaks, why is this so?[/color]

          From the fine manual
          (http://www.python.org/doc/current/li...example.html):

          A testcase is created by subclassing unittest.TestCa se. The three
          individual tests are defined with methods whose names start with
          the letters "test". This naming convention informs the test runner
          about which methods represent tests.

          The convention is necessary because you might want methods that are
          *not* tests.

          -- David Goodger


          Comment

          • Zunbeltz Izaola

            #6
            Re: unittest

            David Goodger <goodger@python .org> writes:
            [color=blue]
            > Zunbeltz Izaola wrote:[color=green]
            > > Tnaks, why is this so?[/color]
            >
            > From the fine manual
            > (http://www.python.org/doc/current/li...example.html):
            >
            > A testcase is created by subclassing unittest.TestCa se. The three
            > individual tests are defined with methods whose names start with
            > the letters "test". This naming convention informs the test runner
            > about which methods represent tests.[/color]

            I have to read the manuals at full :-)

            Zunbeltz
            [color=blue]
            >
            > The convention is necessary because you might want methods that are
            > *not* tests.
            >
            > -- David Goodger[/color]

            Comment

            Working...