def test_str_of_exception():
    """Test the str() representation of an exception."""
    from System import NullReferenceException, Convert, FormatException

    e = NullReferenceException('')
    assert str(e) == ''

    e = NullReferenceException('Something bad happened')
    assert str(e).startswith('Something bad happened')

    with pytest.raises(FormatException) as cm:
        Convert.ToDateTime('this will fail')
Esempio n. 2
0
    def testStrOfException(self):
        """Test the str() representation of an exception."""
        from System import NullReferenceException
        from System import Convert, FormatException

        e = NullReferenceException('')
        self.failUnless(str(e) == '')

        e = NullReferenceException('Something bad happened')
        self.failUnless(str(e).startswith('Something bad happened'))

        try:
            Convert.ToDateTime('this will fail')
        except FormatException, e:
            self.failUnless(str(e).find('at System.DateTime.Parse') > -1)
Esempio n. 3
0
    def testStrOfException(self):
        """Test the str() representation of an exception."""
        from System import NullReferenceException
        from System import Convert, FormatException
        e = NullReferenceException('')
        self.failUnlessEqual(str(e), '')

        e = NullReferenceException('Something bad happened')
        self.failUnless(str(e).startswith('Something bad happened'))

        try:
            Convert.ToDateTime('this will fail')
        except FormatException, e:
            msg = unicode(e).encode(
                "utf8")  # fix for international installation
            self.failUnless(msg.find('System.Convert.ToDateTime') > -1, msg)
Esempio n. 4
0
def test_str_of_exception():
    """Test the str() representation of an exception."""
    from System import NullReferenceException, Convert, FormatException

    e = NullReferenceException('')
    assert str(e) == ''

    e = NullReferenceException('Something bad happened')
    assert str(e).startswith('Something bad happened')

    with pytest.raises(FormatException) as cm:
        Convert.ToDateTime('this will fail')

    e = cm.value
    # fix for international installation
    msg = text_type(e).encode("utf8")
    fnd = text_type('System.Convert.ToDateTime').encode("utf8")
    assert msg.find(fnd) > -1, msg
def test_raise_instance_exception():
    """Test instance exception propagation."""
    from System import NullReferenceException

    with pytest.raises(NullReferenceException) as cm:
        raise NullReferenceException()

    exc = cm.value
    assert isinstance(exc, NullReferenceException)
    assert len(exc.Message) > 0
def test_raise_class_exception_with_value():
    """Test class exception propagation with associated value."""
    from System import NullReferenceException

    with pytest.raises(NullReferenceException) as cm:
        raise NullReferenceException('Aiiieee!')

    exc = cm.value
    assert isinstance(exc, NullReferenceException)
    assert exc.Message == 'Aiiieee!'
def test_raise_instance_exception_with_args():
    """Test instance exception propagation with args."""
    from System import NullReferenceException

    with pytest.raises(NullReferenceException) as cm:
        raise NullReferenceException("Aiiieee!")

    exc = cm.value
    assert isinstance(exc, NullReferenceException)
    assert exc.Message == 'Aiiieee!'
def test_exc_info():
    """Test class exception propagation.
    Behavior of exc_info changed in Py3. Refactoring its test"""
    from System import NullReferenceException
    try:
        raise NullReferenceException("message")
    except Exception as exc:
        type_, value, tb = sys.exc_info()
        assert type_ is NullReferenceException
        assert value.Message == "message"
        assert exc.Message == "message"
        # FIXME: Lower-case message isn't implemented
        # self.assertTrue(exc.message == "message")
        assert value is exc
Esempio n. 9
0
    def testRaiseInstanceException(self):
        """Test instance exception propagation."""
        from System import NullReferenceException

        def test():
            raise NullReferenceException()

        self.assertRaises(NullReferenceException, test)

        try:
            raise NullReferenceException()
        except:
            type, value, tb = sys.exc_info()
            self.assertTrue(type is NullReferenceException)
            self.assertTrue(isinstance(value, NullReferenceException))
            self.assertTrue(len(value.Message) > 0)
Esempio n. 10
0
    def testRaiseClassExceptionWithValue(self):
        """Test class exception propagation with associated value."""
        from System import NullReferenceException

        def test():
            raise NullReferenceException('Aiiieee!')

        self.assertRaises(NullReferenceException, test)

        try:
            raise NullReferenceException('Aiiieee!')
        except:
            type, value, tb = sys.exc_info()
            self.assertTrue(type is NullReferenceException)
            self.assertTrue(isinstance(value, NullReferenceException))
            self.assertTrue(value.Message == 'Aiiieee!')
Esempio n. 11
0
    def testRaiseInstanceExceptionWithArgs(self):
        """Test instance exception propagation with args."""
        from System import NullReferenceException

        def test():
            raise NullReferenceException("Aiieeee!")

        self.assertRaises(NullReferenceException, test)

        try:
            raise NullReferenceException('Aiiieee!')
        except:
            type, value, tb = sys.exc_info()
            self.assertTrue(type is NullReferenceException)
            self.assertTrue(isinstance(value, NullReferenceException))
            self.assertTrue(value.Message == 'Aiiieee!')
Esempio n. 12
0
 def test():
     raise NullReferenceException('Aiiieee!')
Esempio n. 13
0
 def test():
     raise NullReferenceException("Aiieeee!")
Esempio n. 14
0
 def test():
     raise NullReferenceException()
Esempio n. 15
0
 def raiseNullRefEx():
     raise NullReferenceException()