intfprgm / intfprgm / tests.py

#!/usr/bin/env python

import unittest

from intfprgm import interface, abstract, concrete


class InterfaceTest(unittest.TestCase):

    def test_init(self):
        @interface
        class test:
            pass
        self.assertRaises(SyntaxError, test)

    def test_method_raise(self):
        class test:
            def __init__(self):
                pass
        self.assertRaises(SyntaxError, interface, test)

    def test_method_okay(self):
        class test:
            def __init__(self):
                raise NotImplementedError()
        interface(test)

    def test_abstract(self):
        class test1:
            def method(self):
                pass
        class test2:
            @abstract
            def method(self):
                pass
        self.assertRaises(SyntaxError, interface, test1)
        interface(test2)


class AbstractTest(unittest.TestCase):

    def test_init(self):
        @abstract
        class test:
            def method(self):
                raise NotImplementedError()
        self.assertRaises(SyntaxError, test)

    def test_method(self):
        class test:
            pass
        self.assertRaises(SyntaxError, abstract, test)

    def test_okay(self):
        class test1:
            def method(self):
                raise NotImplementedError
        abstract(test1)

        class test2:
            def method(self):
                '''doctring'''
                raise NotImplementedError
        abstract(test2)

        class test3:
            def method(self):
                raise NotImplementedError()
        abstract(test3)

        class test4:
            def method(self):
                '''docstring'''
                raise NotImplementedError()
        abstract(test4)

    def test_function(self):
        @abstract
        def raises():
            pass
        self.assertRaises(NotImplementedError, raises)


class ConcreteTest(unittest.TestCase):

    def test_raise(self):
        class test1:
            def method(self):
                raise NotImplementedError
        self.assertRaises(SyntaxError, concrete, test1)

        class test2:
            def method(self):
                raise NotImplementedError()
        self.assertRaises(SyntaxError, concrete, test2)

    def test_not_raise(self):
        class test:
            def method(self):
                return NotImplementedError()
        concrete(test)

    def test_subclass(self):
        class parent(object):
            def override_me(self):
                raise NotImplementedError()
        class test(parent):
            def leave_it(self):
                pass
        self.assertRaises(SyntaxError, concrete, test)

    def test_abstract(self):
        class test1:
            def method(self):
                pass
        class test2:
            @abstract
            def method(self):
                pass
        concrete(test1)
        self.assertRaises(SyntaxError, concrete, test2)


if __name__ == '__main__':
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.