def generate_content(self):
        """Generates a test case as a string."""
        # Setup pre-conditions.
        if not self.variance:
            logging.error("%s: No variance information %s", self.id(), self.variance)
            sys.exit(-1)

        for var in self.variable.values():
            var.clear()

        # Handle variances
        variances = []
        for _ in range(random.randint(DharmaConst.VARIANCE_MIN, DharmaConst.VARIANCE_MAX)):
            var = random.choice(list(self.variance.values()))
            variances.append(DharmaConst.VARIANCE_TEMPLATE % var.generate(GenState()))
            variances.append("\n")

        # Handle variables
        variables = []
        for var in self.variable.values():
            if var.default:
                variables.append(DharmaConst.VARIANCE_TEMPLATE % var.default)
                variables.append("\n")

        # Build content
        content = "".join(chain([self.prefix], variables, variances, [self.suffix]))
        if self.template:
            return Template(self.template).safe_substitute(testcase_content=content)
        return content
def generate_content ( self ) : if not self . variance : logging . error ( "%s: No variance information %s" , self . id ( ) , self . variance ) sys . exit ( - 1 ) for var in self . variable . values ( ) : var . clear ( ) variances = [ ] for _ in range ( random . randint ( DharmaConst . VARIANCE_MIN , DharmaConst . VARIANCE_MAX ) ) : var = random . choice ( list ( self . variance . values ( ) ) ) variances . append ( DharmaConst . VARIANCE_TEMPLATE % var . generate ( GenState ( ) ) ) variances . append ( "\n" ) variables = [ ] for var in self . variable . values ( ) : if var . default : variables . append ( DharmaConst . VARIANCE_TEMPLATE % var . default ) variables . append ( "\n" ) content = "" . join ( chain ( [ self . prefix ] , variables , variances , [ self . suffix ] ) ) if self . template : return Template ( self . template ) . safe_substitute ( testcase_content = content ) return content
Generates a test case as a string.