Example #1
0
    def setUp(self):
        """
        **Public Method**
        
        The execution of the various JKind permutations are actually
        executed here. The results are stashed away in the internal
        results and exceptions data members for testing later.
        
        """
        self.results = ResultList()
        self.exceptions = list()
        GuiIF().setFileUnderTest(self.file)

        # Print test header for nicer output formatting
        print("\n**********************************************")
        print(self.beginTestTag + str(self.file))

        for arg in self.args:
            GuiIF().setArgUnderTest(arg)
            jk = JKind(self.file, arg, jkindPath=self.jkindJar, javaPath=self.javaPath, quiet=self.quiet)
            jk.run()

            # Do not append None-type result returns
            if jk.getResults() != None:
                self.results.append(jk.getResults())

            # Ok, and desirable to append None-type exception returns
            self.exceptions.append(jk.getException())
Example #2
0
    def testBadLen( self ):
        '''
        Test that our Results List class can deal with mis-matching count of 
        results.
        '''

        # This is a list of JKind Results read from the file
        testlst = self.jk._results

        # Create a specialized results list for testing
        explst = ResultList()

        # The hand-coded Results are correct, except left out the 'var2' entry
        # to see that the Results list class will detect this.
        res = JKindResult( '', '' )
        res['name'] = 'var1'
        res['answer'] = 'valid'
        res['K'] = '0'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var3'
        res['answer'] = 'valid'
        res['K'] = '2'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var4'
        res['answer'] = 'valid'
        res['K'] = '3'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var5'
        res['answer'] = 'falsifiable'
        res['K'] = '6'
        explst.append( res )

        self.assertNotEqual( testlst, explst, 'Test expected to fail' )
Example #3
0
    def testFailName( self ):
        '''
        Test expected to Fail
        '''

        # This is a list of JKind Results read from the file
        testlst = self.jk._results

        # Create a specialized results list for testing
        explst = ResultList()


        # This first name is intentionally incorrect
        res = JKindResult( '', '' )
        res['name'] = 'var'  # << WRONG on purpose
        res['answer'] = 'valid'
        res['K'] = '0'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var2'
        res['answer'] = 'valid'
        res['K'] = '1'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var3'
        res['answer'] = 'valid'
        res['K'] = '2'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var4'
        res['answer'] = 'valid'
        res['K'] = '3'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var5'
        res['answer'] = 'falsifiable'
        res['K'] = '6'
        explst.append( res )

        self.assertNotEqual( testlst, explst, 'Test exepected to fail' )
Example #4
0
    def testReadSuccess( self ):
        '''
        Test that the Properties (Variables) match what we expect
        '''

        # This is a list of JKind Results read from the file
        testlst = self.jk._results

        # Create a specialized results list for testing
        explst = ResultList()

        res = JKindResult( '', '' )
        res['name'] = 'var1'
        res['answer'] = 'valid'
        res['K'] = '0'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var2'
        res['answer'] = 'valid'
        res['K'] = '1'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var3'
        res['answer'] = 'valid'
        res['K'] = '2'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var4'
        res['answer'] = 'valid'
        res['K'] = '3'
        explst.append( res )

        res = JKindResult( '', '' )
        res['name'] = 'var5'
        res['answer'] = 'falsifiable'
        res['K'] = '6'
        explst.append( res )


        self.assertEqual( testlst, explst, 'Test the read and expected lists' )
Example #5
0
class _JKTestCase(unittest.TestCase):
    """
    **Private Class**
    
    Think of this as an Abstract Base Class (though this concept doesn't
    exist in Python).
    
    This is the one-and-only test case explicity written for this test suite.
    The class factory sub-classes this and adds the filename and arguments
    to dynamically create the multitude of test cases added to the
    unittest.TestSuite for execution.
    
    """

    def __init__(self, methodName="runTest"):
        """
        **Constructor**
        
        Calls the TestCase super constructor. Passes along the 
        methodName argument.
        
        :param methodName: Defaults to "runTest". Typically not specified
                           and letting the default take precedence.
        :type methodName: runner method
        
        """
        unittest.TestCase.__init__(self, methodName=methodName)

    def setUp(self):
        """
        **Public Method**
        
        The execution of the various JKind permutations are actually
        executed here. The results are stashed away in the internal
        results and exceptions data members for testing later.
        
        """
        self.results = ResultList()
        self.exceptions = list()
        GuiIF().setFileUnderTest(self.file)

        # Print test header for nicer output formatting
        print("\n**********************************************")
        print(self.beginTestTag + str(self.file))

        for arg in self.args:
            GuiIF().setArgUnderTest(arg)
            jk = JKind(self.file, arg, jkindPath=self.jkindJar, javaPath=self.javaPath, quiet=self.quiet)
            jk.run()

            # Do not append None-type result returns
            if jk.getResults() != None:
                self.results.append(jk.getResults())

            # Ok, and desirable to append None-type exception returns
            self.exceptions.append(jk.getException())

    def tearDown(self):
        """
        **Public Method**
        
        Just prints to stdout that the test is done. No other action.
        
        """
        print("\n")
        print(self.endTestTag + str(self.file))

    def test_result(self):
        """
        **Public Method**
        
        This is where the test assertions for the results and exceptions are
        made.
        
        Iterates through the results of the JKind runs and tests that the 
        results of the individual runs per file do not change based on the
        differing arguments. 
        
        Also checks if any Java Exceptions were raised during the JKind 
        executions. 
        
        All assertions are performed as "subTest", meaning that an assertion
        failure will not end this method.
        
        """

        # First test the JKind Results
        resultsList = self.results.copy()
        controlList = resultsList.pop()
        controlList.sort()

        for each in resultsList:

            with self.subTest("subtest results"):

                each.sort()
                ok = controlList == each
                GuiIF().logSubTestResult(ok)
                self.assertTrue(ok, "Test File: " + self.file)

        # Now check for any Java exceptions that may have occurred
        for excp in self.exceptions:

            with self.subTest("subtest exceptions"):
                try:
                    msg = "Exception Occurred-> {} {}".format(excp.text, excp.args)
                except AttributeError:
                    msg = "Exception Occurrred"
                self.assertIsNone(excp, msg)