Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 183a5a4439
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 92 lines (68 sloc) 3.053 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
# Test the ri module

import os, os.path, shutil
import unittest
import cgkit.ri
import cgkit.cri
import ritest

class TestRi(unittest.TestCase):
    
    def setUp(self):
        tmpDir = os.path.join("tmp")
        if not os.path.exists("tmp"):
            os.mkdir("tmp")
        
# def tearDown(self):
# shutil.rmtree("tmp", ignore_errors=True)
    
    def testRiModule(self):
        """Check the ri module."""

        if os.path.exists("tmp/riout.rib"):
            os.remove("tmp/riout.rib")
        if os.path.exists("tmp/include.rib"):
            os.remove("tmp/include.rib")

        ritest.main(cgkit.ri, "tmp/riout.rib", archiveName="tmp/include.rib")
        
        f = file("tmp/riout_norm.rib", "wt")
        ritest.normalizeRIB(file("tmp/riout.rib", "rt"), f)
        f.close()

        f = file("tmp/include_norm.rib", "wt")
        ritest.normalizeRIB(file("tmp/include.rib", "rt"), f)
        f.close()
        
        self.assertFiles("tmp/riout_norm.rib", "data/riout_ref.rib")
        self.assertFiles("tmp/include_norm.rib", "data/include_ref.rib")
        
    def testCRiModule(self):
        """Check the cri module."""
        print ("cri test is disabled")
        return

        if os.path.exists("tmp/criout.rib"):
            os.remove("tmp/criout.rib")
        if os.path.exists("tmp/cinclude.rib"):
            os.remove("tmp/cinclude.rib")

# ri = cgkit.cri.loadRI(None)
        ri = cgkit.cri.loadRI("3delight")
# ri = cgkit.cri.loadRI("ri")
# ri = cgkit.cri.loadRI("aqsislib")
# ri = cgkit.cri.loadRI("ri2rib")
# ri = cgkit.cri.loadRI("prman")
# ri.RiProcFree = None

        ritest.main(ri, "tmp/criout.rib", archiveName="tmp/cinclude.rib")
        
        f = file("tmp/criout_norm.rib", "wt")
        ritest.normalizeRIB(file("tmp/criout.rib", "rt"), f)
        f.close()

        f = file("tmp/cinclude_norm.rib", "wt")
        ritest.normalizeRIB(file("tmp/cinclude.rib", "rt"), f)
        f.close()
        
        self.assertFiles("tmp/criout_norm.rib", "data/riout_ref.rib")
        self.assertFiles("tmp/cinclude_norm.rib", "data/cinclude_ref.rib")
        
        
    def assertFiles(self, fileName, refFileName):
        lines = file(fileName, "rt").readlines()
        reflines = file(refFileName, "rt").readlines()
        linenr = 0
        for line,refline in zip(lines, reflines):
            line = line.rstrip()
            refline = refline.rstrip()
            linenr += 1
            self.assertEqual(line, refline, "Mismatch in line %d: '%s' != '%s'"%(linenr, line.strip()[:30], refline.strip()[:30]))
            
        if len(lines)<len(reflines):
            self.fail('"%s" has too few lines'%fileName)
        elif len(lines)>len(reflines):
            self.fail('"%s" has too many lines'%fileName)
                

######################################################################

if __name__=="__main__":
    unittest.main()
Something went wrong with that request. Please try again.