#!/usr/bin/env python
# Version: $Header: /compromis/home/xmlschemata/cvs/downloads/python/xvif/outie/test-suite.py,v 1.1 2003/03/12 15:06:49 vdv Exp $

"""
The contents of this file are subject to the Mozilla Public License  Version 1.1 (the "License"); you may not use this file except in  compliance with the License. 
You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
Software distributed under the License is distributed on an "AS IS"  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the  License for the specific language governing rights and limitations under  the License. 

The Original Code is available at http://downloads.xmlschemata.org/python/xvif/

The Initial Developer of the Original Code is Eric van der Vlist. Portions  created by Eric van der Vlist are Copyright (C) 2002. All Rights Reserved. 

Relax NG is a specification edited by the OASIS RELAX NG Technical Committee:
http://www.oasis-open.org/committees/relax-ng/

This implementation uses the implementation notes written by James Clark:
http://www.thaiopensource.com/relaxng/implement.html

Contributor(s): 
"""

import unittest
import outie
import copy
import os
import re
import sys

class TestOutie(unittest.TestCase):
	
	def run1test(self):
		global suite
		print self._TestCase__testMethodName
		dir = "%s/%s/" % (suite, self._TestCase__testMethodName[4:])
		os.chdir(dir)
		schema = "c.xml"
		for F in os.listdir("."):
			if F.rfind(".xml") == len(F)-4 and F.find(".v.") != -1 :
				o = outie.Outie(schema, F)
				self.failUnless(o.validate(), "should be valid (%s)" % F)
			elif F.rfind(".xml") == len(F)-4 and F.find(".i.") != -1 :
				valid = F.find(".v.") != -1 
				o = outie.Outie(schema, F)
				self.failUnless(not o.validate(), "should not be valid (%s)" % F)
		os.chdir("../..")

if __name__ == "__main__":
	if len(sys.argv) > 1: 
		suite = sys.argv[1]
	else:
		suite = "tests"
	print suite
	for rep in os.listdir(suite):
		if re.match("\d{3}", rep):
			f =  lambda self: self.run1test()
			setattr(TestOutie, "test"+rep, f)
	unittest.TestProgram(argv=[sys.argv[0]]) # Just pretend that there were no args :-)

