예제 #1
0
    def test_should_dot(self):
        should.be_an_integer.or_string.and_equal(1)
        # (integer) OR (string AND equal 1)

        should.be_an_integer.or_a_float.or_a_string
        # (integer) OR (float) OR (string)
        should.be_an_integer.or_a_string.and_equal_to(10).or_a_float
        # (integer) OR (string AND equal 10) OR (float)

        should.be_an_integer.or_a_string.but_less_than(10)
        # (integer OR string) AND (less than 10)

        # Note: we can use spacing to make them easier to read
        should.be_an_integer.or_a_string.and_equal(0).or_a_float
        # (integer) OR (string AND equal 0) OR (float)

        # Note: in this case we use capitalization to make them more obvious
        should.be_an_integer.Or_a_string.And_equal(1).But_Not_be_a_float
        # ( (integer) OR (string AND equal 1) ) AND (not float)

        # Note: if no matchers are given the last one is used
        should.be_equal_to(10).Or(20).Or(30)
        # (equal 10) OR (equal 20) OR (equal 30)

        # Note: If no combinator is given AND is used by default
        should.integer.greater_than(10).less_than(20)
        # (integer) AND (greater than 10) AND (less than 20)

        # Note: But by using should_either we can set OR as default
        should_either.equal(10).equal(20).equal(30)
 def get_deployment_env_info(self, name, namespace):
     env_cmd = f'oc get deploy {name} -n {namespace} "jsonpath={{.spec.template.spec.containers[0].env}}"'
     env, exit_code = self.cmd.run(env_cmd)
     exit_code | should.be_equal_to(0)
     env_from_cmd = f'oc get deploy {name} -n {namespace} "jsonpath={{.spec.template.spec.containers[0].envFrom}}"'
     env_from, exit_code = self.cmd.run(env_from_cmd)
     exit_code | should.be_equal_to(0)
     return env, env_from
예제 #3
0
파일: openshift.py 프로젝트: mliker/jenkins
 def set_env_for_deployment_config(self, name, namespace, key, value):
     env_cmd = f'oc -n {namespace} set env dc/{name} {key}={value}'
     print("oc set command: {}".format(env_cmd))
     output, exit_code = self.cmd.run(env_cmd)
     exit_code | should.be_equal_to(0)
     time.sleep(3)
     return output, exit_code
예제 #4
0
def before_scenario(_context, _scenario):
    print("\nGetting OC status before {} scenario".format(_scenario))
    code, output = subprocess.getstatusoutput('oc get project default')
    print("[CODE] {}".format(code))
    print("[CMD] {}".format(output))
    code | should.be_equal_to(0)
    print("***Connected to cluster***")
예제 #5
0
def then_envFrom_contains(context, app_name, sbr_name1, sbr_name2):
    time.sleep(60)
    openshift = Openshift()
    result = openshift.get_deployment_envFrom_info(app_name,
                                                   context.namespace.name)
    result | should.be_equal_to("[map[secretRef:map[name:binding-request-1]] map[secretRef:map[name:binding-request-2]]]")\
        .desc(f'{app_name} deployment should contain secretRef: {sbr_name1} and {sbr_name2}')
예제 #6
0
def expect_person_class_box_and_keypoint_detections_for_every_frame(
        expected_result, result):
    boxes_gt = expected_result["boxes"]
    boxes_result = result["boxes"]
    len(boxes_result) | should.be_equal_to(len(boxes_gt))
    keypoints_gt = expected_result["keypoints"]
    keypoints_result = result["keypoints"]
    len(keypoints_result) | should.be_equal_to(len(keypoints_gt))
    cls_ix_person = get_person_class_index()
    # each element in boxes is a list indexed by class ids,
    # e.g. boxes[i][cls_ix_person] are box detections for cls_ix_person
    # (which happens to be 1) in frame i
    all_of([len(x)
            for x in boxes_result]).should.be_greater_than(cls_ix_person)
    # # the same goes for keypoints...
    all_of([len(x)
            for x in keypoints_result]).should.be_greater_than(cls_ix_person)
 def check_for_deployment_status(self,
                                 deployment_name,
                                 namespace,
                                 wait_for_status="True"):
     deployment_status_cmd = f'oc get deployment {deployment_name} -n {namespace} -o "jsonpath={{.status.conditions[*].status}}"'
     deployment_status, exit_code = self.cmd.run_wait_for_status(
         deployment_status_cmd, wait_for_status, 5, 300)
     exit_code | should.be_equal_to(0)
     return deployment_status
예제 #8
0
def it_accurately_estimates_3d_poses_for_a_video(video_dir, video_file,
                                                 expected_frames_header,
                                                 expected_frames_processed):
    collected_progress = []

    def collect_progress(state, meta):
        collected_progress.append((state, meta))

    # we need a fake celery task to run the detect job
    task = __AttrDict({
        "request": __AttrDict({"id": "test"}),
        "update_state": collect_progress
    })
    video_dir = fixture_path(video_dir)
    video_path = os.path.join(video_dir, video_file)
    video_dims = get_video_dims(video_path)
    result_meta = estimate_poses_task(task, video_path, "anything{}")
    result_meta | should.be_equal_to(
        {
            "status": "success",
            "resultFile": f"{video_dir}/out/pose_estimations_3d.npz",
            "resultUrl": "anythingtest",
            "resultPoses3dUrl": "anythingtest/poses3d",
            "resultPoses2dUrl": "anythingtest/poses2d",
            "resultVisualizationFile":
            f"{video_dir}/out/pose_estimates_3d.mp4",
            "resultVisualizationUrl": "anythingtest/visualization",
        })
    # expect_progress_callbacks(
    #     collected_progress, expected_frames_header, expected_frames_processed
    # )
    result_npz = np.load(result_meta["resultFile"])
    result = {k: result_npz[k] for k in result_npz.files}
    result_kps_3d = result["output_keypoints_3d"]
    ground_truth_path = os.path.join(video_dir,
                                     "keypoints_3d_ground_truth.npy")
    expected_kps_3d = np.load(ground_truth_path)
    expected_result_shape = (expected_frames_processed, 17, 3)
    expected_kps_3d.shape | should.be_equal_to(expected_result_shape)
    result_kps_3d.shape | should.be_equal_to(expected_result_shape)
    expect_3d_keypoint_estimates_for_every_frame_accurate_within_margin_of_error(
        expected_kps_3d, result_kps_3d, video_dims)
예제 #9
0
 def get_resource_info_by_jq(self, resource_type, name, namespace, jq_expression, wait=False):
     output, exit_code = self.cmd.run(f'oc get {resource_type} {name} -n {namespace} -o json | jq -rc \'{jq_expression}\'')
     if exit_code != 0:
         if wait:
             attempts = 5
             while exit_code != 0 and attempts > 0:
                 output, exit_code = self.cmd.run(f'oc get {resource_type} {name} -n {namespace} -o json | jq -rc \'{jq_expression}\'')
                 attempts -= 1
                 time.sleep(5)
     exit_code | should.be_equal_to(0).desc(f'Exit code should be 0:\n OUTPUT:\n{output}')
     return output.rstrip("\n")
예제 #10
0
 def get_resource_info_by_jsonpath(self, resource_type, name, namespace, json_path, wait=False):
     output, exit_code = self.cmd.run(f'oc get {resource_type} {name} -n {namespace} -o "jsonpath={json_path}"')
     if exit_code != 0:
         if wait:
             attempts = 5
             while exit_code != 0 and attempts > 0:
                 output, exit_code = self.cmd.run(f'oc get {resource_type} {name} -n {namespace} -o "jsonpath={json_path}"')
                 attempts -= 1
                 time.sleep(5)
     exit_code | should.be_equal_to(0).desc(f'Exit code should be 0:\n OUTPUT:\n{output}')
     return output
예제 #11
0
def before_scenario(_context, _scenario):
    '''
    before_scenario(context, scenario), after_scenario(context, scenario)
    These run before and after each scenario is run.
    The scenario passed in is an instance of Scenario.
'''
    print(
        colored.yellow(
            "Checking cluster environment for {} scenario".format(_scenario)))
    code, output = subprocess.getstatusoutput('oc get project default')
    print(colored.yellow("[CODE] {}".format(code)))
    print(colored.yellow("[CMD] {}".format(output)))
    code | should.be_equal_to(0)
    print(colored.green("*************Connected to cluster*************"))
예제 #12
0
def check_secret_key_value(context, secret_name, secret_key, secret_value):
    openshift = Openshift()
    json_path = f'{{.data.{secret_key}}}'
    output = openshift.get_resource_info_by_jsonpath("secrets", secret_name, context.namespace.name, json_path)
    timeout = 180
    interval = 5
    attempts = timeout/interval
    while True:
        actual_secret_value = base64.b64decode(output).decode('ascii')
        if (secret_value == actual_secret_value) or attempts <= 0:
            break
        else:
            attempts -= 1
            time.sleep(interval)
            output = openshift.get_resource_info_by_jsonpath("secrets", secret_name, context.namespace.name, json_path)
    result = base64.decodebytes(bytes(output, 'utf-8'))
    result | should.be_equal_to(bytes(secret_value, 'utf-8'))
예제 #13
0
 def get_resource_info_by_jsonpath(self,
                                   resource_type,
                                   name,
                                   namespace,
                                   json_path,
                                   wait=False,
                                   interval=5,
                                   timeout=120):
     oc_cmd = f'oc get {resource_type} {name} -n {namespace} -o "jsonpath={json_path}"'
     output, exit_code = self.cmd.run(oc_cmd)
     if exit_code != 0 or output == "" or output == "<nil>":
         if wait:
             attempts = timeout / interval
             while (exit_code != 0 or output == ""
                    or output == "<nil>") and attempts > 0:
                 output, exit_code = self.cmd.run(oc_cmd)
                 attempts -= 1
                 time.sleep(interval)
     exit_code | should.be_equal_to(0).desc(
         f'Exit code should be 0:\n OUTPUT:\n{output}')
     return output
 def get_configmap(self, namespace):
     output, exit_code = self.cmd.run(f'oc get cm -n {namespace}')
     exit_code | should.be_equal_to(0)
     return output
예제 #15
0
def verify_injected_secretRef(context, secret_ref, cr_name, crd_name, json_path):
    time.sleep(60)
    openshift = Openshift()
    result = openshift.get_resource_info_by_jsonpath(crd_name, cr_name, context.namespace.name, json_path, wait=True, timeout=180)
    result | should.be_equal_to(secret_ref).desc(f'Failed to inject secretRef "{secret_ref}" in "{cr_name}" at path "{json_path}"')
예제 #16
0
def expect_3d_estimates_for_every_frame_for_same_number_of_keypoints_as_ground_truth(
        expected_3d_kps, result_3d_kps):
    type(expected_3d_kps) | should.be_equal_to(np.ndarray)
    type(result_3d_kps) | should.be_equal_to(np.ndarray)
    result_3d_kps.shape | should.be_equal_to(expected_3d_kps.shape)
 def get_resource_lst(self, resource_plural, namespace):
     (output, exit_code) = self.cmd.run(f'oc get {resource_plural} -n {namespace} -o "jsonpath={{.items['
                                        f'*].metadata.name}}"')
     exit_code | should.be_equal_to(0)
     return output
예제 #18
0
def pyshould_test_sample():
    import unittest
    # from pyshould import *
    import pyshould.patch
    from pyshould import should
    result | should.be_integer()
    (1 + 1) | should_not.equal(1)
    "foo" | should.equal('foo')
    len([1, 2, 3]) | should.be_greater_than(2)
    result | should.equal(1 / 2 + 5)
    1 | should_not.eq(2)
    # Matchers not requiring a param can skip the call parens
    True | should.be_truthy
    # Check for exceptions with the context manager interface
    with should.throw(TypeError):
        raise TypeError('foo')
    with should.not_raise:  # will report a failure
        fp = open('does-not-exists.txt')
    # Apply our custom logic for a test
    'FooBarBaz' | should.pass_callback(lambda x: x[3:6] == 'Bar')
    should.be_an_integer.or_string.and_equal(1)
    # (integer) OR (string AND equal 1)
    should.be_an_integer.or_a_float.or_a_string
    # (integer) OR (float) OR (string)
    should.be_an_integer.or_a_string.and_equal_to(10).or_a_float
    # (integer) OR (string AND equal 10) OR (float)
    should.be_an_integer.or_a_string.but_less_than(10)
    # (integer OR string) AND (less than 10)
    # Note: we can use spacing to make them easier to read
    should.be_an_integer.or_a_string.and_equal(0).or_a_float
    # (integer) OR (string AND equal 0) OR (float)
    # Note: in this case we use capitalization to make them more obvious
    should.be_an_integer.Or_a_string.And_equal(1).But_Not_be_a_float
    # ( (integer) OR (string AND equal 1) ) AND (not float)
    # Note: if no matchers are given the last one is used
    should.be_equal_to(10).Or(20).Or(30)
    # (equal 10) OR (equal 20) OR (equal 30)
    # Note: If no combinator is given AND is used by default
    should.integer.greater_than(10).less_than(20)
    # (integer) AND (greater than 10) AND (less than 20)
    # Note: But by using should_either we can set OR as default
    should_either.equal(10).equal(20).equal(30)

    class TestSequenceFunctions1(unittest.TestCase):
        def setUp(self):
            self.seq = list(range(10))

        def test_shuffle(self):
            # make sure the shuffled sequence does not lose any elements
            random.shuffle(self.seq)
            self.seq.sort()
            self.assertEqual(self.seq, list(range(10)))
            # should raise an exception for an immutable sequence
            self.assertRaises(TypeError, random.shuffle, (1, 2, 3))

        def test_choice(self):
            element = random.choice(self.seq)
            a = 10
            a | should.gt(20)

        def test_sample(self):
            with self.assertRaises(ValueError):
                random.sample(self.seq, 20)
            for element in random.sample(self.seq, 5):
                self.assertTrue(element in self.seq)

    unittest.main()
 def get_route(self, route_name, namespace):
     output, exit_code = self.cmd.run(f'oc get route {route_name} -n {namespace}')
     exit_code | should.be_equal_to(0)
     return output
 def get_route_host(self, name, namespace):
     (output, exit_code) = self.cmd.run(
         f'oc get route {name} -n {namespace} -o "jsonpath={{.status.ingress[0].host}}"')
     exit_code | should.be_equal_to(0)
     return output
 def get_role_binding(self, namespace):
     output, exit_code = self.cmd.run(f'oc get rolebinding -n {namespace}')
     exit_code | should.be_equal_to(0)
     return output
 def get_service_account(self, namespace):
     output, exit_code = self.cmd.run(f'oc get sa -n {namespace}')
     exit_code | should.be_equal_to(0)
     return output
 def get_deploymentconfig(self, namespace):
     output, exit_code = self.cmd.run(f'oc get dc -n {namespace}')
     exit_code | should.be_equal_to(0)
     return output
예제 #24
0
def then_app_is_connected_to_db(context, db_name):
    application = context.application
    app_db_name = application.get_db_name_from_api(wait=True)
    app_db_name | should.be_equal_to(db_name)
예제 #25
0
def then_app_is_connected_to_db(context, db_name):
    application = context.nodejs_app
    app_db_name = application.get_db_name_from_api()
    app_db_name | should.be_equal_to(db_name)