コード例 #1
0
    def initialize_material(self):
        # setup input data
        self.kwargs = self.material.kwargs

        # setup the first, last indices
        self.real_space_first = self.material.real_space_first
        self.real_space_last = self.material.real_space_last

        data = load_data(self.material.real_space_filename)
        self.r = data[:, get_index_of_function("r", RealSpaceHeaders)]
        self.gofr = data[:, get_index_of_function("g(r)", RealSpaceHeaders)]
        self.GofR = data[:, get_index_of_function("G(r)", RealSpaceHeaders)]
        self.GKofR = data[:, get_index_of_function("GK(r)", RealSpaceHeaders)]

        # targets for 1st peaks
        self.gofr_ff_target = self.material.gofr_ff_target
        self.GofR_ff_target = self.material.GofR_ff_target
        self.GKofR_ff_target = self.material.GKofR_ff_target

        data = load_data(self.material.reciprocal_space_filename)
        self.q = data[:, get_index_of_function("Q", ReciprocalSpaceHeaders)]
        self.sq = data[:,
                       get_index_of_function("S(Q)", ReciprocalSpaceHeaders)]
        self.fq = data[:,
                       get_index_of_function("Q[S(Q)-1]",
                                             ReciprocalSpaceHeaders)]
        self.fq_keen = data[:,
                            get_index_of_function("FK(Q)",
                                                  ReciprocalSpaceHeaders)]
        self.dcs = data[:,
                        get_index_of_function("DCS(Q)", ReciprocalSpaceHeaders
                                              )]
コード例 #2
0
def test_sample3():
    dir = Path('tests/sample_3')
    gt_BoundingBoxes = load_data(dir / 'groundtruths.json')
    pd_BoundingBoxes = load_data(dir / 'detections.json')

    RESULT0_5 = json.load(open(dir / 'expected0_5.json'))
    results = get_pascal_voc_metrics(gt_BoundingBoxes, pd_BoundingBoxes, .5)
    assert_results(results, RESULT0_5, 'ap')
    assert_results(results, RESULT0_5, 'precision')
    assert_results(results, RESULT0_5, 'recall')

    results = get_pascal_voc_metrics(gt_BoundingBoxes, pd_BoundingBoxes, .3)
    assert_results(results, RESULT0_3, 'ap')
コード例 #3
0
def test_get_signatures_with_digest_reference(hostname):
    all_signatures = signatures_matching = json.loads(load_data("sigs_with_reference"))
    signatures_matching["data"] = all_signatures["data"][0:2]
    manifest_to_search = "sha256:dummy-manifest-digest-1"
    reference_to_search = (
        "registry.redhat.io/e2e-container/rhel-8-e2e-container-test-"
        "product:latest,registry.access.redhat.com/e2e-container/rhel-8-e2e-container-test-"
        "product:latest"
    )
    url_with_digest_ref = (
        "{0}v1/signatures?filter=manifest_digest=in=({1}),reference=in=({2})".format(
            hostname, manifest_to_search, reference_to_search
        )
    )
    with requests_mock.Mocker() as m:
        m.get(
            url_with_digest_ref,
            json=signatures_matching,
        )

        my_client = pyxis_client.PyxisClient(hostname, 5, None, 3, True)
        res = my_client.get_container_signatures(
            manifest_to_search, reference_to_search
        )
        assert res == signatures_matching["data"]
        assert m.request_history[0].url == url_with_digest_ref
コード例 #4
0
ファイル: test_converter.py プロジェクト: Kvieta1990/pystog
    def initialize_material(self):
        # setup input data
        self.kwargs = self.material.kwargs

        # setup the tolerance
        self.first = self.material.reciprocal_space_first
        self.last = self.material.reciprocal_space_last

        data = load_data(self.material.reciprocal_space_filename)
        self.q = data[:, get_index_of_function("Q", ReciprocalSpaceHeaders)]
        self.sq = data[:,
                       get_index_of_function("S(Q)", ReciprocalSpaceHeaders)]
        self.fq = data[:,
                       get_index_of_function("Q[S(Q)-1]",
                                             ReciprocalSpaceHeaders)]
        self.fq_keen = data[:,
                            get_index_of_function("FK(Q)",
                                                  ReciprocalSpaceHeaders)]
        self.dcs = data[:,
                        get_index_of_function("DCS(Q)", ReciprocalSpaceHeaders
                                              )]

        # targets for 1st peaks
        self.sq_target = self.material.sq_target
        self.fq_target = self.material.fq_target
        self.fq_keen_target = self.material.fq_keen_target
        self.dcs_target = self.material.dcs_target
コード例 #5
0
def test_get_signatures_manifests_file(capsys):
    hostname = "https://pyxis.remote.host/"

    data_file_path = "@tests/data/manifest_digests.json"
    signatures_matching = json.loads(load_data("sigs_with_reference"))
    manifest_digest = (
        "sha256:dummy-manifest-digest-1,sha256:sha256:dummy-manifest-digest-2")
    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--manifest-digest",
        data_file_path,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
    ]

    expected = json.dumps(signatures_matching["data"],
                          sort_keys=True,
                          indent=4,
                          separators=(",", ": "))

    with requests_mock.Mocker() as m:
        m.get(
            "{0}v1/signatures?filter=manifest_digest=in=({1})".format(
                hostname, manifest_digest),
            json=signatures_matching,
        )
        pyxis_ops.get_signatures_main(args)
    out, _ = capsys.readouterr()
    assert out == expected
コード例 #6
0
def test_get_signatures(capsys, hostname):
    all_signatures = signatures_matching = json.loads(
        load_data("sigs_with_reference"))
    manifest_digest = "sha256:dummy-manifest-digest-1"
    reference = "registry.access.redhat.com/e2e-container/rhel-8-e2e-container-test-product:latest"
    signatures_matching["data"] = all_signatures["data"][0:3]
    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--manifest-digest",
        manifest_digest,
        "--reference",
        reference,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
    ]

    expected = json.dumps(signatures_matching["data"],
                          sort_keys=True,
                          indent=4,
                          separators=(",", ": "))

    with requests_mock.Mocker() as m:
        m.get(
            "{0}v1/signatures?filter=manifest_digest=in=({1}),reference=in=({2})"
            .format(hostname, manifest_digest, reference),
            json=signatures_matching,
        )
        pyxis_ops.get_signatures_main(args)
    out, _ = capsys.readouterr()
    assert out == expected
コード例 #7
0
def test_upload_signature_error_timeout(capsys):
    """Test a connection error which persists after a few attempts."""
    hostname = "https://pyxis.remote.host/"

    data = load_data("signatures")

    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
        "--signatures",
        data,
    ]

    with requests_mock.Mocker() as m:
        m.post("{0}v1/signatures".format(hostname),
               exc=requests.exceptions.ConnectTimeout)

        with pytest.raises(requests.exceptions.ConnectTimeout):
            pyxis_ops.upload_signatures_main(args)

    out, err = capsys.readouterr()
    assert out == ""
    assert err == ""
コード例 #8
0
def test_upload_signature_json(capsys, hostname):
    items_to_upload = load_data("signatures")
    responses = json.loads(load_response("post_signatures_ok"))

    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
        "--signatures",
        items_to_upload,
    ]

    with requests_mock.Mocker() as m:
        m.post(
            urljoin(hostname, "/v1/signatures"),
            [{
                "status_code": 200,
                "json": resp
            } for resp in responses],
        )

        retval = pyxis_ops.upload_signatures_main(args)

        assert len(retval) == len(responses)
        assert all(ret_item in responses for ret_item in retval)

    out, _ = capsys.readouterr()
    assert all(resp["signature_data"] in out for resp in responses)
コード例 #9
0
def test_sample2():
    dir = Path('tests/sample_2')
    gt_BoundingBoxes = load_data(dir / 'groundtruths.json')
    pd_BoundingBoxes = load_data(dir / 'detections.json')

    RESULT0_5 = json.load(open(dir / 'expected0_5.json'))
    results = get_pascal_voc_metrics(gt_BoundingBoxes, pd_BoundingBoxes, .5)
    assert_results(results, RESULT0_5, 'ap')
    assert_results(results, RESULT0_5, 'precision')
    assert_results(results, RESULT0_5, 'recall')
    assert_results(results, RESULT0_5, 'tp')
    assert_results(results, RESULT0_5, 'fp')
    assert_results(results, RESULT0_5, 'num_groundtruth')
    assert_results(results, RESULT0_5, 'num_detection')

    mAP = MetricPerClass.mAP(results)
    assert np.isclose(RESULT0_5['mAP'], mAP, 1e-3), mAP
コード例 #10
0
def test_get_signatures_from_multiple_pages(hostname):
    page_1_response = json.loads(load_data("signatures_page1"))
    page_2_response = json.loads(load_data("signatures_page2"))
    manifest_to_search = (
        "sha256:dummy-manifest-digest-1, sha256:dummy-manifest-digest-2"
    )
    with requests_mock.Mocker() as m:
        m.get(
            "{0}v1/signatures?filter=manifest_digest=in=({1})".format(
                hostname, manifest_to_search
            ),
            json=page_1_response,
        )
        m.get(
            "{0}v1/signatures?filter=manifest_digest=in=({1})&page=1".format(
                hostname, manifest_to_search
            ),
            json=page_2_response,
        )

        my_client = pyxis_client.PyxisClient(hostname, 5, None, 3, True)
        res = my_client.get_container_signatures(manifest_to_search, None)
        assert res == page_1_response["data"] + page_2_response["data"]
コード例 #11
0
ファイル: test_converter.py プロジェクト: Kvieta1990/pystog
    def initialize_material(self):
        # setup input data
        self.kwargs = self.material.kwargs

        # setup the tolerance
        self.first = self.material.real_space_first
        self.last = self.material.real_space_last

        data = load_data(self.material.real_space_filename)
        self.r = data[:, get_index_of_function("r", RealSpaceHeaders)]
        self.gofr = data[:, get_index_of_function("g(r)", RealSpaceHeaders)]
        self.GofR = data[:, get_index_of_function("G(r)", RealSpaceHeaders)]
        self.GKofR = data[:, get_index_of_function("GK(r)", RealSpaceHeaders)]

        # targets for 1st peaks
        self.gofr_target = self.material.gofr_target
        self.GofR_target = self.material.GofR_target
        self.GKofR_target = self.material.GKofR_target
コード例 #12
0
def test_upload_signatures_server_error_json_detail(capsys):
    """
    Test error response with additional details as JSON.

    Verify that in case of an erroneus response from the server not only the
    status code (e.g. 400) and reason (e.g. "Client Error") are displayed, but
    also the response content, because it may contain crucial information.
    """
    hostname = "https://pyxis.remote.host/"

    data = load_data("signatures")

    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
        "--signatures",
        data,
    ]

    with requests_mock.Mocker() as m:
        m.post(
            "{0}v1/signatures".format(hostname),
            status_code=400,
            reason="Crunchy frog",
            text='{"detail": "Extremely nasty"}',
        )

        err_msg = "400 Client Error: Crunchy frog for url: .+\nExtremely nasty"
        with pytest.raises(requests.exceptions.HTTPError, match=err_msg):
            pyxis_ops.upload_signatures_main(args)

    out, err = capsys.readouterr()
    assert out == ""
    assert err == ""
コード例 #13
0
def test_upload_signatures_server_error_content(capsys):
    """
    Test error response with additional details as non-JSON content.

    Verify that in case of an error the extra details from the response are
    shown even if we failed to parse the content as JSON.
    """
    hostname = "https://pyxis.remote.host/"

    data = load_data("signatures")

    args = [
        "dummy",
        "--pyxis-server",
        hostname,
        "--pyxis-ssl-crtfile",
        "/root/name.crt",
        "--pyxis-ssl-keyfile",
        "/root/name.key",
        "--signatures",
        data,
    ]

    with requests_mock.Mocker() as m:
        m.post(
            "{0}v1/signatures".format(hostname),
            status_code=400,
            reason="Crunchy frog",
            text="Extra non-JSON info",
        )

        err_msg = "400 Client Error: Crunchy frog for url: .+\nExtra non-JSON info"
        with pytest.raises(requests.exceptions.HTTPError, match=err_msg):
            pyxis_ops.upload_signatures_main(args)

    out, err = capsys.readouterr()
    assert out == ""
    assert err == ""
コード例 #14
0
ファイル: busta_rhymes.py プロジェクト: vdorbs/cs155-mp3
def busta_rhymes(path='data/shakespeare.txt'):
    data = load_data(path)
    rhymes = {}
    pairs = []
    rhyme_sets = []
    for sonnet in data:
        pairs.extend([(lw(sonnet[i]), lw(sonnet[i + 2]))
                      for i in range(0, 9, 4)])
        pairs.append((lw(sonnet[-2]), lw(sonnet[-1])))
    while pairs != []:
        rhyme_set = set(pairs.pop())
        for i, pair in enumerate(pairs):
            if not rhyme_set.isdisjoint(set(pair)):
                rhyme_set |= set(pair)
                pairs.pop(i)
        rhyme_sets.append(rhyme_set)
    for rhyme_set in rhyme_sets:
        for word in rhyme_set:
            s = rhyme_set.copy()
            s.discard(word)
            rhymes[word] = list(s)
    with open('data/rhyming_dictionary.json', 'w') as fh:
        fh.write(json.dumps(rhymes))
コード例 #15
0
import json
from pathlib import Path

from podm.podm import get_pascal_voc_metrics
from podm.visualize import plot_precision_recall_curve_all
from tests.utils import load_data

if __name__ == '__main__':
    dir = Path('sample_2')
    gt_BoundingBoxes = load_data(dir / 'groundtruths.json')
    pd_BoundingBoxes = load_data(dir / 'detections.json')

    results = get_pascal_voc_metrics(gt_BoundingBoxes, pd_BoundingBoxes, .5)
    plot_precision_recall_curve_all(results,
                                    dir / 'plots',
                                    show_interpolated_precision=True)