pytilities.test.overloading.parameter

Package pytilities :: Package test :: Package overloading :: Module parameter |
[hide private]
[frames] | no frames]

# Source Code for Module pytilities.test.overloading.parameter

      1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net>
      2  #
      3  # This file is part of pytilities.
      4  #
      5  # pytilities is free software: you can redistribute it and/or modify
      6  # it under the terms of the GNU General Public License as published by
      7  # the Free Software Foundation, either version 3 of the License, or
      8  # (at your option) any later version.
      9  #
     10  # pytilities is distributed in the hope that it will be useful,
     11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  # GNU General Public License for more details.
     14  #
     15  # You should have received a copy of the GNU General Public License
     16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>.
     17  #
     18
     19  __docformat__ = 'reStructuredText'
     20
     21  import unittest
     22
     23  # TODO: write more unit tests for the new functionality, same for Composite
     24  from pytilities.overloading import Param
     25
     26 -class CtorTestCase(unittest.TestCase):
     27 -    def test_ctor(self):
     28          """Test success and fail cases"""
     29          p = Param("mir")
     30
     31          Param("mir", int)
     32          Param("mir", default=0)
     33          Param("mir", int, 0)
     34          Param("mir", int, default=0)
     35          Param("mir", type_=int, default=0)
     36
     37          self.assertRaises(AssertionError, Param, "")
     38          self.assertRaises(AssertionError, Param, None)
     39          self.assertRaises(AssertionError, Param, "mir", int, default="frr")
     40          self.assertRaises(AssertionError, Param, "mir", int, 0, default=5)
     41
     42 -class ArgPresentTestCase(unittest.TestCase):
     43 -    def setUp(self):
     44          self.kwargs = {"mir":3, "muff":8}
     45
     46 -    def test_name(self):
     47          p = Param("mir")
     48          self.assert_(p.read_kwargs(self.kwargs))
     49
     50          d = {}
     51          p.write(d)
     52          self.assertEquals(d, {"mir": 3})
     53
     54 -    def test_type(self):
     55          p = Param("mir", int)
     56          self.assert_(p.read_kwargs(self.kwargs))
     57
     58          d = {}
     59          p.write(d)
     60          self.assertEquals(d, {"mir": 3})
     61
     62          self.assertFalse(p.read_kwargs({"mir": "stingstring"}))
     63
     64 -    def test_default(self):
     65          p = Param("mir", default=0)
     66          self.assert_(p.read_kwargs(self.kwargs))
     67
     68          d = {}
     69          p.write(d)
     70          self.assertEquals(d, {"mir": 3})
     71
     72 -    def test_type_with_default(self):
     73          p = Param("mir", int, 0)
     74          self.assert_(p.read_kwargs(self.kwargs))
     75
     76          d = {}
     77          p.write(d)
     78          self.assertEquals(d, {"mir": 3})
     79
     80          self.assertFalse(p.read_kwargs({"mir": "stingstring"}))
     81
     82 -class ArgMissingTestCase(unittest.TestCase):
     83 -    def setUp(self):
     84          self.kwargs = {"muff": 8}
     85
     86 -    def test_name(self):
     87          p = Param("mir")
     88          self.assertFalse(p.read_kwargs(self.kwargs))
     89
     90 -    def test_type(self):
     91          p = Param("mir", int)
     92          self.assertFalse(p.read_kwargs(self.kwargs))
     93
     94 -    def test_default(self):
     95          p = Param("mir", default=0)
     96          self.assert_(p.read_kwargs(self.kwargs))
     97
     98          d = {}
     99          p.write(d)
    100          self.assertEquals(d, {"mir": 0})
    101
    102 -    def test_type_with_default(self):
    103          p = Param("mir", int, 0)
    104          self.assert_(p.read_kwargs(self.kwargs))
    105
    106          d = {}
    107          p.write(d)
    108          self.assertEquals(d, {"mir": 0})
    109
    110          self.assertFalse(p.read_kwargs({"mir": "stingstring"}))
    111