def setUp( self ):
        self.testFile1 = './unit_test/test_files/order_1.xml'
        self.testFile2 = './unit_test/test_files/order_2.xml'

        # Instantiate the JKind classes
        self.jk1 = JKind( 'dummy', 'dummy' )
        self.jk2 = JKind( 'dummy', 'dummy' )

        # Don't actually run JKind, but rather sneak our known XML file
        # in through the private read method.
        self.jk1._parseXML( self.testFile1 )
        self.jk2._parseXML( self.testFile2 )
    def setUp( self ):
        self.testFile = './unit_test/test_files/tc_xml_read.xml'

        # Instantiate the JKind class.
        self.jk = JKind( 'dummy', 'dummy' )

        # Don't actually run JKind, but rather sneak our known XML file
        # in through the private read method.
        self.jk._parseXML( self.testFile )
Exemple #3
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())
class TC_XmlRead( unittest.TestCase ):

    def setUp( self ):
        self.testFile = './unit_test/test_files/tc_xml_read.xml'

        # Instantiate the JKind class.
        self.jk = JKind( 'dummy', 'dummy' )

        # Don't actually run JKind, but rather sneak our known XML file
        # in through the private read method.
        self.jk._parseXML( self.testFile )


    def tearDown( self ):
        pass


    def testFileExists( self ):
        '''
        First make sure the path is correct for the test file
        '''
        exists = os.path.exists( os.path.abspath( self.testFile ) )
        self.assertTrue( exists, 'File Under Test Exists?' )


    def testResultsLength( self ):
        '''
        Test that the Length of the Results list matches our expectation
        '''
        listLen = len( self.jk._results )
        EXP_LIST_LEN = 5
        self.assertEqual( EXP_LIST_LEN, listLen, "Results List is Length?" )


    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' )


    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' )


    def testFailAnswer( 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'] = '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'] = 'falsifiable'  # << Intentionally Wrong
        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' )


    def testFailK( 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'] = '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'] = '99'  # << Intentionally Wrong
        explst.append( res )

        self.assertNotEqual( testlst, explst, 'Test exepected to fail' )


    def testPassK( 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'] = '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'] = '99'  # << Intentionally set K to different value
        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 exepected to fail' )


    def testPassUnknown( self ):
        '''
        Test expected to Pass
        '''

        # 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'] = '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'] = 'unknown'  # << Intentionally set to unknown
        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 exepected to fail' )


    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' )
class TC_XmlOrder( unittest.TestCase ):

    def setUp( self ):
        self.testFile1 = './unit_test/test_files/order_1.xml'
        self.testFile2 = './unit_test/test_files/order_2.xml'

        # Instantiate the JKind classes
        self.jk1 = JKind( 'dummy', 'dummy' )
        self.jk2 = JKind( 'dummy', 'dummy' )

        # Don't actually run JKind, but rather sneak our known XML file
        # in through the private read method.
        self.jk1._parseXML( self.testFile1 )
        self.jk2._parseXML( self.testFile2 )


    def tearDown( self ):
        pass


    def testFileExists( self ):
        '''
        First make sure the path is correct for the test files
        '''
        exists = os.path.exists( os.path.abspath( self.testFile1 ) )
        self.assertTrue( exists, 'File Under Test 1 Exists?' )

        exists = os.path.exists( os.path.abspath( self.testFile2 ) )
        self.assertTrue( exists, 'File Under Test 2 Exists?' )


    def testResultsLength( self ):
        '''
        Test that the Length of the Results list matches our expectation
        '''
        EXP_LIST_LEN = 4

        listLen = len( self.jk1._results )
        self.assertEqual( EXP_LIST_LEN, listLen, "Results List is Length?" )

        listLen = len( self.jk2._results )
        self.assertEqual( EXP_LIST_LEN, listLen, "Results List is Length?" )


    def testFail( self ):
        testlst1 = self.jk1._results
        testlst2 = self.jk2._results

        ok = ( testlst1 == testlst2 )

        self.assertFalse( ok, 'Results should not be equal' )

        # The second and third Properties in the XML files are out of order
        # and should've generated a failure string. Check that this is true.
        a = testlst1[1].failures()
        self.assertEqual( len( a ), 1, 'Second Property should have failure string' )

        b = testlst1[2].failures()
        self.assertEqual( len( b ), 1, 'Third Property should have failure string' )


    def testSuccess( self ):
        '''
        Test that the Properties (Variables) match what we expect.
        The order of the Properties are intentionally out of order in the XML file.
        This checks that our ResultsList can be sorted prior to equality testing.
        '''

        # This is a list of JKind Results read from the file
        testlst1 = self.jk1._results.copy()
        testlst2 = self.jk2._results.copy()

        testlst1.sort()
        testlst2.sort()

        ok = ( testlst1 == testlst2 )

        for jkr in testlst1:
            for line in jkr.failures():
                print( line )

        self.assertTrue( ok, 'Test the results' )