Exemplo n.º 1
0
def test_loader():

    local_root_dir = mkdtemp()

    # create a loader with a new temporary directory
    loader1 = Loader(local_root_dir=local_root_dir)

    # locate requirements.txt, after cloning the repo
    local_path = loader1.find_file("requirements", ["https://github.com/imodels/simgen.git"], implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(os.path.join(local_root_dir,'imodels','simgen','requirements.txt'))

    # create a new loader with the same temp dir
    loader2 = Loader(local_root_dir=local_root_dir)

    # locate requirements.txt, after pulling the repo
    local_path = loader2.find_file("requirements", ["https://github.com/imodels/simgen.git"], implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(os.path.join(local_root_dir,'imodels','simgen','requirements.txt'))

    # create a new offline loader with explicit github url to local directory association
    loader3 = Loader()
    loader3.add_repo("https://github.com/imodels/simgen.git", os.path.realpath(os.path.join(local_root_dir,'imodels','simgen')))

    # locate requirements.txt locally
    local_path = loader3.find_file("requirements", ["https://github.com/iModels/simgen.git"], implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(os.path.join(local_root_dir,'imodels','simgen','requirements.txt'))
Exemplo n.º 2
0
def test_ast():

    # create a new offline loader with explicit github url to local directory association
    loader = Loader()
    loader.add_repo("https://github.com/imodels/simgen.git", os.path.split(os.path.dirname(__file__))[0])

    ast_node = AstNode(file_name='prg', loader=loader, search_path=['https://github.com/imodels/simgen/res/ast_test'])

    assert ast_node is not None
    assert ast_node.nodetype_name == 'add'
    assert ast_node.mapping['add'] is not None
    assert ast_node.mapping['add']['expr1'] is not None
    assert ast_node.mapping['add']['expr2'] is not None

    ast_node.validate()
def run():
    # # configure logging
    # logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=0)

    # create a simulated online loader with explicit github url to local directory association
    loader = Loader()
    local_repo_dir = os.path.join(os.path.dirname(__file__),'..','..')
    loader.add_repo("https://github.com/imodels/simgen.git", local_repo_dir)

    # # initialize a project
    project = Project('https://github.com/imodels/simgen/res/binary_lj_sim/online_project.yaml', loader)

    generated_code = project.render('binary_lj_sim_prg', output_dir='./generated_code')

    print("Generated code:\n {}".format(generated_code))
    print("Additional files have been saved to: ./generated_code")
Exemplo n.º 4
0
def test_ast():

    # create a new offline loader with explicit github url to local directory association
    loader = Loader()
    loader.add_repo("https://github.com/imodels/simgen.git",
                    os.path.split(os.path.dirname(__file__))[0])

    ast_node = AstNode(
        file_name='prg',
        loader=loader,
        search_path=['https://github.com/imodels/simgen/res/ast_test'])

    assert ast_node is not None
    assert ast_node.nodetype_name == 'add'
    assert ast_node.mapping['add'] is not None
    assert ast_node.mapping['add']['expr1'] is not None
    assert ast_node.mapping['add']['expr2'] is not None

    ast_node.validate()
Exemplo n.º 5
0
def run():
    # # configure logging
    # logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=0)

    # create a simulated online loader with explicit github url to local directory association
    loader = Loader()
    local_repo_dir = os.path.join(os.path.dirname(__file__), '..', '..')
    loader.add_repo("https://github.com/imodels/simgen.git", local_repo_dir)

    # # initialize a project
    project = Project(
        'https://github.com/imodels/simgen/res/binary_lj_sim/online_project.yaml',
        loader)

    generated_code = project.render('binary_lj_sim_prg',
                                    output_dir='./generated_code')

    print("Generated code:\n {}".format(generated_code))
    print("Additional files have been saved to: ./generated_code")
Exemplo n.º 6
0
def test_loader():

    local_root_dir = mkdtemp()

    # create a loader with a new temporary directory
    loader1 = Loader(local_root_dir=local_root_dir)

    # locate requirements.txt, after cloning the repo
    local_path = loader1.find_file("requirements",
                                   ["https://github.com/imodels/simgen.git"],
                                   implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(
        os.path.join(local_root_dir, 'imodels', 'simgen', 'requirements.txt'))

    # create a new loader with the same temp dir
    loader2 = Loader(local_root_dir=local_root_dir)

    # locate requirements.txt, after pulling the repo
    local_path = loader2.find_file("requirements",
                                   ["https://github.com/imodels/simgen.git"],
                                   implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(
        os.path.join(local_root_dir, 'imodels', 'simgen', 'requirements.txt'))

    # create a new offline loader with explicit github url to local directory association
    loader3 = Loader()
    loader3.add_repo(
        "https://github.com/imodels/simgen.git",
        os.path.realpath(os.path.join(local_root_dir, 'imodels', 'simgen')))

    # locate requirements.txt locally
    local_path = loader3.find_file("requirements",
                                   ["https://github.com/iModels/simgen.git"],
                                   implicit_ext=['', '.txt'])
    assert local_path is not None
    assert os.path.realpath(local_path) == os.path.realpath(
        os.path.join(local_root_dir, 'imodels', 'simgen', 'requirements.txt'))