Пример #1
0
def run_test():
    numexemplars = 10
    testgrammarfile = "flofree.cfdg"
    testdir = "test-save-exemplars"
    savefilename = "{0}/flofree.png".format(testdir)
    if os.path.isdir(testdir):
        shutil.rmtree(testdir)
    print "Creating directory {0}...".format(testdir)
    os.mkdir(testdir)

    # Create grammar
    print "Creating grammar from file '{0}'...".format(testgrammarfile)
    g = gramparse.grammar_from_file(testgrammarfile)

    # Generate <numexemplars> exemplars
    print "Generating {0} exemplars...".format(numexemplars)
    exemplars = exgen.generate_exemplars(g, numexemplars, debug=True)
    assert len(exemplars) == numexemplars, \
        "Expected {0} exemplars to be generated, " \
        "instead have {1}".format(numexemplars, len(exemplars))

    # Saving exemplars to separate files
    print "Exemplars successfully generated. Saving exemplars to files..."
    for i, ex in list(enumerate(exemplars)):
        savefilename = saveutils.first_available_filename(savefilename)
        print "Saving exemplar {0} of {1} to {2}".format(i+1, numexemplars, savefilename)
        exsave.save_image(ex, savefilename)

    print "All exemplars successfully saved!"
Пример #2
0
def run_test():
    testgrammarfile = "flofree.cfdg"
    testdir = "test-save-exemplar"
    newfilename = "{0}/flofree.png".format(testdir)
    if not os.path.isdir(testdir):
        print "Creating directory {0}...".format(testdir)
        os.mkdir(testdir)

    # Create grammar
    print "Creating grammar from file '{0}'...".format(testgrammarfile)
    g = gramparse.grammar_from_file(testgrammarfile)

    print "Running CFDG with grammar body..."
    exemplar = exgen.generate_exemplar(g)

    print "Saving exemplar image to '{0}'...".format(
        saveutils.first_available_filename(newfilename))
    exemplar.save_image(newfilename)

    print "Exemplar successfully saved!"
Пример #3
0
def run_test():
    global g
    global v

    filename = "clouds.cfdg"
    dirname = "test-save-variant"
    newfilename = "{0}/test-save-variant.cfdg".format(dirname)
    if not os.path.isdir(dirname):
        print "Creating directory {0}...".format(dirname)
        os.mkdir(dirname)

    print "Reading grammar from file: " + filename + "..."
    g = gramparse.grammar_from_file(filename)

    print "Creating variant from grammar..."
    v = gramgen.generate_variant(g, 1, 5)

    print "Saving variant to file: " + \
          saveutils.first_available_filename(newfilename)
    gramsave.save(v, newfilename)

    print "Variant successfully saved!"