Exemplo n.º 1
0
def test_library_add(caplog):
    from fusesoc.main import add_library
    from fusesoc.coremanager import CoreManager

    # Set up safe environment variables for library location
    os.environ['XDG_DATA_HOME'] = library_root

    tcf = tempfile.NamedTemporaryFile(mode="w+")
    clone_target = "tests/test_libraries"

    conf = Config(file=tcf)
    conf.library_root = library_root
    cm = CoreManager(conf)

    args = Namespace()

    args.name = 'fusesoc-cores'
    args.location = clone_target
    args.config = tcf
    args.no_auto_sync = False
    vars(args)['sync-uri'] = sync_uri

    add_library(cm, args)

    expected = """[library.fusesoc-cores]
sync-uri = https://github.com/fusesoc/fusesoc-cores
location = {}""".format(os.path.abspath(clone_target))

    tcf.seek(0)
    result = tcf.read().strip()

    assert expected == result

    tcf.close()
    shutil.rmtree(clone_target)
    tcf = tempfile.NamedTemporaryFile(mode="w+")

    args.config = tcf
    args.location = None
    vars(args)['sync-type'] = 'git'

    expected = """[library.fusesoc-cores]
sync-uri = https://github.com/fusesoc/fusesoc-cores
sync-type = git"""

    add_library(cm, args)

    tcf.seek(0)
    result = tcf.read().strip()

    assert expected == result

    tcf.close()
    shutil.rmtree(os.path.join(library_root, "fusesoc"))
    tcf = tempfile.NamedTemporaryFile(mode="w+")

    args.config = tcf
    vars(args)['sync-type'] = 'local'
    vars(args)['sync-uri'] = 'tests/capi2_cores'
    args.location = None

    with caplog.at_level(logging.INFO):
        add_library(cm, args)

    assert "Interpreting sync-uri 'tests/capi2_cores' as location for local provider." in caplog.text
Exemplo n.º 2
0
def test_library_add(caplog):
    import tempfile
    from fusesoc.main import add_library
    from fusesoc.coremanager import CoreManager
    from fusesoc.librarymanager import LibraryManager

    tcf = tempfile.NamedTemporaryFile(mode="w+")
    clone_target = tempfile.mkdtemp(prefix="library_add_")
    library_root = tempfile.mkdtemp(prefix="library_add_")
    conf = Config(file=tcf)
    conf.library_root = library_root
    cm = CoreManager(conf)
    args = Namespace()

    args.name = "fusesoc-cores"
    args.location = clone_target
    args.config = tcf
    args.no_auto_sync = False
    vars(args)["sync-uri"] = sync_uri

    add_library(cm, args)

    expected = """[library.fusesoc-cores]
location = {}
sync-uri = https://github.com/fusesoc/fusesoc-cores
sync-type = git
auto-sync = true""".format(os.path.abspath(clone_target))

    tcf.seek(0)
    result = tcf.read().strip()

    assert expected == result

    tcf.close()

    tcf = tempfile.NamedTemporaryFile(mode="w+")

    args.config = tcf
    args.location = None
    vars(args)["sync-type"] = "git"

    expected = """[library.fusesoc-cores]
location = fusesoc_libraries/fusesoc-cores
sync-uri = https://github.com/fusesoc/fusesoc-cores
sync-type = git
auto-sync = true""".format(cm._lm.library_root)

    add_library(cm, args)

    tcf.seek(0)
    result = tcf.read().strip()

    assert expected == result
    shutil.rmtree("fusesoc_libraries")
    tcf.close()

    tcf = tempfile.NamedTemporaryFile(mode="w+")

    args.config = tcf
    vars(args)["sync-type"] = "local"
    vars(args)["sync-uri"] = "tests/capi2_cores"
    args.location = None

    with caplog.at_level(logging.INFO):
        add_library(cm, args)

    assert (
        "Interpreting sync-uri 'tests/capi2_cores' as location for local provider."
        in caplog.text)