Ejemplo n.º 1
0
def test_read_write_traceable(lgf_data_dir):
    repo0 = Repository.create_from(str(lgf_data_dir), traceable=True)

    tmp = BytesIO()
    repo0.write(tmp)

    repo1 = Repository.read(tmp)

    assert repo0._Repository__min_shell == repo1._Repository__min_shell
    assert repo0._Repository__max_shell == repo1._Repository__max_shell
    assert repo0._Repository__traceable == repo1._Repository__traceable
    assert repo0._Repository__versioning == repo1._Repository__versioning

    # msgpack writes tuples as lists. this is ok for our purposes, but we need to take care of that in testing!
    assert repo0.charges_iacm.keys() == repo1.charges_iacm.keys()
    for shell_size in repo0.charges_iacm.keys():
        assert repo0.charges_iacm[shell_size].keys(
        ) == repo1.charges_iacm[shell_size].keys()
        for key in repo0.charges_iacm[shell_size].keys():
            assert repo0.charges_iacm[shell_size][key] == [
                tuple(x) for x in repo0.charges_iacm[shell_size][key]
            ]

    assert repo0.charges_elem.keys() == repo1.charges_elem.keys()
    for shell_size in repo0.charges_elem.keys():
        assert repo0.charges_elem[shell_size].keys(
        ) == repo1.charges_elem[shell_size].keys()
        for key in repo0.charges_elem[shell_size].keys():
            assert repo0.charges_elem[shell_size][key] == [
                tuple(x) for x in repo0.charges_elem[shell_size][key]
            ]

    assert repo0.iso_iacm == repo1.iso_iacm
    assert repo0.iso_elem == repo1.iso_elem
Ejemplo n.º 2
0
def test_read_write_versioning(lgf_data_dir):
    repo0 = Repository.create_from(str(lgf_data_dir), versioning=True)

    tmp = BytesIO()
    repo0.write(tmp)

    repo1 = Repository.read(tmp, versioning=True)

    assert repo0._Repository__min_shell == repo1._Repository__min_shell
    assert repo0._Repository__max_shell == repo1._Repository__max_shell
    assert repo0._Repository__traceable == repo1._Repository__traceable
    assert repo0._Repository__versioning == repo1._Repository__versioning

    assert repo0.charges_iacm == repo1.charges_iacm
    assert repo0.charges_elem == repo1.charges_elem
    assert not hasattr(repo0, 'iso_iacm')
    assert not hasattr(repo0, 'iso_elem')
    assert not hasattr(repo1, 'iso_iacm')
    assert not hasattr(repo1, 'iso_elem')

    assert isinstance(
        repo1.charges_iacm[1]['c18208da9e290c6faf8a0c58017d24d9'],
        _VersioningList)
    assert isinstance(
        repo1.charges_iacm[3]['76198d87470cc1b2f871da60449146bc'],
        _VersioningList)
    assert isinstance(
        repo1.charges_elem[1]['92ed00c54b2190be94748bee34b22847'],
        _VersioningList)
    assert isinstance(
        repo1.charges_elem[3]['17ac3199bf634022485c145821f358d5'],
        _VersioningList)
Ejemplo n.º 3
0
def init(repo_location: Optional[str] = None) -> None:
    """Create the charger from a repository.

    Gets the repository location from the command line if none is
    given.

    Args:
        repo_location: The path to the repository to use.

    """
    global _charger
    if not repo_location:
        repo_location = parse_arguments()
    repo = Repository.read(repo_location)
    _charger = CDPCharger(repo, rounding_digits=3)
Ejemplo n.º 4
0
def test_read_write(lgf_data_dir):
    repo0 = Repository.create_from(str(lgf_data_dir))

    tmp = BytesIO()
    repo0.write(tmp)

    repo1 = Repository.read(tmp)

    assert repo0._Repository__min_shell == repo1._Repository__min_shell
    assert repo0._Repository__max_shell == repo1._Repository__max_shell
    assert repo0._Repository__traceable == repo1._Repository__traceable
    assert repo0._Repository__versioning == repo1._Repository__versioning

    assert repo0.charges_iacm == repo1.charges_iacm
    assert repo0.charges_elem == repo1.charges_elem
    assert not hasattr(repo0, 'iso_iacm')
    assert not hasattr(repo0, 'iso_elem')
    assert not hasattr(repo1, 'iso_iacm')
    assert not hasattr(repo1, 'iso_elem')
Ejemplo n.º 5
0

if __name__ == '__main__':
    test_data_dir = os.path.realpath(
        os.path.join(__file__, '..', 'cross_validation_data'))

    if len(sys.argv) != 3:
        print('Usage: {} bucket num_buckets'.format(sys.argv[0]))
        print('Got {} arguments.'.format(len(sys.argv) - 1))
        quit()

    bucket = int(sys.argv[1])
    num_buckets = int(sys.argv[2])

    repo_file = 'cross_validation_repository.zip'
    repo = Repository.read(repo_file)

    cross_validate('MeanCharger', False, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('MeanCharger', True, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('MedianCharger', False, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('MedianCharger', True, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('ModeCharger', False, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('ModeCharger', True, 3, test_data_dir, repo, bucket,
                   num_buckets)
    cross_validate('ILPCharger', False, 3, test_data_dir, repo, bucket,
                   num_buckets)