Ejemplo n.º 1
0
def test_filesystem(tmp_path, database):
    """Test loading and using a queue with the filesystem database.
    """
    from rse.main import Encyclopedia

    config_dir = os.path.join(str(tmp_path), "software")
    os.mkdir(config_dir)
    config_file = os.path.join(config_dir, "rse.ini")

    # System exit if doesn't exist
    with pytest.raises(SystemExit):
        enc = Encyclopedia(config_file=config_file)

    enc = Encyclopedia(config_file=config_file,
                       generate=True,
                       database=database)
    assert enc.config.configfile == config_file

    assert os.path.exists(config_dir)
    assert enc.config_dir == config_dir
    assert enc.config.configfile == os.path.join(enc.config_dir, "rse.ini")
    assert enc.database == database
    assert enc.db.database == database
    if database == "filesystem":
        assert enc.db.data_base == os.path.join(config_dir, "database")

    # Test list, empty without anything
    assert not enc.list()

    # Add a repo
    repo = enc.add("github.com/singularityhub/sregistry")
    assert len(enc.list()) == 1

    # enc.get should return last repo, given no id
    lastrepo = enc.get()
    assert lastrepo.uid == repo.uid

    # Summary
    enc.summary()
    enc.summary("github.com/singularityhub/sregistry")
    enc.analyze("github.com/singularityhub/sregistry")
    enc.analyze_bulk()

    # Clean up a specific repo (no prompt)
    enc.clear(repo.uid, noprompt=True)
    assert len(enc.list()) == 0
    enc.clear(noprompt=True)
    assert not enc.list()

    # Get the taxonomy or criteria
    enc.list_taxonomy()
    enc.list_criteria()
Ejemplo n.º 2
0
def analyze(args, extra):
    """analyze is intended to provide calculations for repos, by default including
    all taxonomy categories and criteria. For a custom set, the user should
    interact with the client directly.
    """
    client = Encyclopedia(config_file=args.config_file, database=args.database)
    result = client.analyze(repo=args.repo,
                            cthresh=args.cthresh,
                            tthresh=args.tthresh)

    # Create rows for criteria and taxonomy
    clookup = {c["uid"]: c for c in client.list_criteria()}
    tlookup = {t["uid"]: t for t in client.list_taxonomy()}
    crows = [[response, clookup[uid]["name"]]
             for uid, response in result["criteria"].items()]
    trows = [[str(count), tlookup[uid]["name"]]
             for uid, count in result["taxonomy"].items()]

    bot.info(f"Summary for {result['repo']}")
    bot.info("\nCriteria")
    bot.table(crows)
    bot.info("\nTaxonomy")
    bot.table(trows)