def run(kwargs): expected = "sanity testmode algorithm".split() for expect in expected: if expect not in kwargs: raise TypeError("Expected argument '%s' not found" % expect) arguments = kwargs.pop('sanity') if len(kwargs) < len(arguments): raise TypeError("Missing Arguements: %s" % ' '.join([a for a in arguments if a not in kwargs])) testmode = kwargs['testmode'] if testmode: import contract from Genetic import mutation, crossover, fitness, individual, population from Genetic.individual import Individual #@UnusedImport contract.checkmod(__name__) for mod in [ crossover, fitness, individual, mutation, population, selection, vis ]: contract.checkmod(mod) kwargs.pop('algorithm')(kwargs)
def run(kwargs): expected = "sanity testmode algorithm".split() for expect in expected: if expect not in kwargs: raise TypeError("Expected argument '%s' not found" %expect) arguments = kwargs.pop('sanity') if len(kwargs) < len(arguments): raise TypeError("Missing Arguements: %s" %' '.join([a for a in arguments if a not in kwargs])) testmode = kwargs['testmode'] if testmode: import contract from Genetic import mutation, crossover, fitness, individual, population from Genetic.individual import Individual #@UnusedImport contract.checkmod(__name__) for mod in [crossover, fitness, individual, mutation, population, selection, vis]: contract.checkmod(mod) kwargs.pop('algorithm')(kwargs)
def extract_text(element): # for testing if type(element) in (list, tuple): return u''.join([extract_text(x) for x in element]) elif isinstance(element, Text): return element.text else: return u''.join([extract_text(x) for i1, i2, x in \ element.iter_childs()]) return u'' if debug: #enable contract checking import contract contract.checkmod(__name__) print "enabled contracts" def test_00(): "homogenize" global debug debug = True assert str(homogenize([G([T('X')]), T('0'), T('1')])) == \ "[G([T('X'), T('0'), T('1')])]" def test_01(): "is_homogeneous" assert not is_homogeneous([G([T('X')]), T('0'), T('1')]) for x in G([T('X')]), G([T('0'), T('1')]):
def grid_to_world(self, v): """Convert a grid coordinate vector to the rendering system's coordinates""" return v * self.block_size # Nat Nat Nat -> Boolean def valid_coords(self, x, y, z): """Determine if the given world coords are valid. pre: isinstance(x, int) or isinstance(x, float) isinstance(y, int) or isinstance(x, float) isinstance(z, int) or isinstance(x, float) """ return (0 <= x < self.size.x and 0 <= y < self.size.y and 0 <= z < self.size.z) # X, Y, Z [Chunk -> [X Y Z -> 'A]] -> 'A def delegate_to_chunk(self, x, y, z, f): """Call f on the chunk at coords (x, y, z) pre: self.valid_coords(x, y, z) """ chunk = self.get_chunk(x, y, z) print x, y, z, chunk.x_off, chunk.y_off, chunk.z_off return f(chunk)(x - chunk.x_off, y - chunk.y_off, z - chunk.z_off) contract.checkmod(__name__)
def _test(): import contract, doctest, testdbc6 contract.checkmod(testdbc6) return doctest.testmod(testdbc6)
def _test(): import contract, doctest, testdbc7 contract.checkmod(testdbc7) return doctest.testmod(testdbc7)
def _test(): import contract, doctest, testdbc1 contract.checkmod(testdbc1, contract.CHECK_ALL) return doctest.testmod(testdbc1)
if __name__ == '__main__': from sys import argv print 'Running tests.' print 'Importing given module' try: module = my_import(argv[1]) except Exception, e: print 'Error while trying to import given module.' print e quit() print 'Checking contracts' try: import contract contract.checkmod(module) except Exception, e: print 'Error while trying to check contracts!' print e print 'Checking doctests' import doctest doctest.testmod(module) # add coverage test here # unit tests? print 'Tests finished.'
def _test(): import contract, doctest, testdbc4 contract.checkmod(testdbc4, contract.CHECK_PRECONDITIONS) return doctest.testmod(testdbc4)