Ejemplo n.º 1
0
    def setUp(self):
        self.parser = Mock()
        self.parser.error = PropertyMock(side_effect=ArgumentError(None, ""))
        
        self.namespace = unittest.mock.MagicMock()
        self.namespace.port = None

        self.action = PortAction(option_strings="", dest="port")
Ejemplo n.º 2
0
class TestPortAction(unittest.TestCase):
    def setUp(self):
        self.parser = Mock()
        self.parser.error = PropertyMock(side_effect=ArgumentError(None, ""))
        
        self.namespace = unittest.mock.MagicMock()
        self.namespace.port = None

        self.action = PortAction(option_strings="", dest="port")

    def test_port_in_range(self):
        self.action.__call__(self.parser, self.namespace, 21)

        self.assertEqual(21, self.namespace.port)

    def test_port_out_of_range(self):
        self.assertRaises(
            ArgumentError, 
            self.action.__call__, 
            parser=self.parser, 
            namespace=self.namespace, 
            values=100000
        )