コード例 #1
0
def _check_table(test: unittest.TestCase, table: pd.DataFrame, colnames):
    test.assertIsInstance(table, pd.DataFrame)
    test.assertGreater(len(table), 0)
    test.assertTrue(table.shape[1], 2)
    test.assertTrue(table.notnull().values.any())
    test.assertTrue((table.iloc[:, 0] != 0).any())
    test.assertEqual(tuple(table.columns), colnames)
コード例 #2
0
 def test_tmx_stackCollisionEvents(self):
     walls = self.game.tilemap.layers['walls']
     destination = walls.cells[walls.cells.keys()[0]]
     (dx, dy) = self.__calcule_delta(self.game.perso, destination)
     self.game.perso.move(dx, dy)
     TestCase.assertEqual(self, len(self.game.tmxEvents), 0)
     self.game.tmx_stackCollisionEvents(self.game.perso,
                                        self.game.tmxEvents)
     TestCase.assertGreater(self, len(self.game.tmxEvents), 0)
コード例 #3
0
 def test_player_stackEvents(self):
     destination = self.game.tilemap.layers['pnjs'].find('monstre')[0]
     (dx, dy) = self.__calcule_delta(self.game.perso, destination)
     self.game.perso.move(dx, dy)
     self.game.player_stackEvents(self.game.perso,
                                  self.game.monster_layer,
                                  self.game.playerEvents)
     TestCase.assertGreater(self, len(self.game.playerEvents), 0)
     TestCase.assertIsInstance(self, self.game.playerEvents[0], Monster)
コード例 #4
0
ファイル: value_assertion.py プロジェクト: emilkarlen/exactly
 def _apply(self, put: unittest.TestCase, value: Sequence[T],
            message_builder: MessageBuilder):
     put.assertGreater(len(value), self.index,
                       message_builder.apply('number of elements'))
     idx = self.index
     element_message_builder = sub_component_builder(_element_at_index(idx),
                                                     message_builder,
                                                     component_separator='')
     self.element_assertion.apply(put, value[idx], element_message_builder)
コード例 #5
0
 def assert_file_does_not_contain(filename: str, search_string: str,
                                  test_case: unittest.TestCase):
     with open(filename, 'r') as file:
         current_line = "\n"
         num_lines = 0
         while current_line:
             current_line = file.readline()
             num_lines += 1
             test_case.assertNotIn(search_string, current_line)
         test_case.assertGreater(num_lines, 1)
コード例 #6
0
 def assert_files_equal(filename_a: str, filename_b: str,
                        test_case: unittest.TestCase):
     with open(filename_a, 'r') as file_a, open(filename_b, 'r') as file_b:
         a_curr = "\n"
         b_curr = a_curr
         num_lines = 0
         while a_curr and b_curr:
             a_curr = file_a.readline()
             b_curr = file_b.readline()
             num_lines += 1
             test_case.assertEqual(a_curr, b_curr)
         test_case.assertGreater(num_lines, 1)
コード例 #7
0
    def run_single_assertions(cls, test: unittest.TestCase,
                              retriever: Retriever):
        data = retriever.retrieve()

        expected_locations = ("0214655255", "0214657975")

        unique_loaded_locations = data.observation_location.unique()

        for location in expected_locations:
            test.assertIn(location, unique_loaded_locations)

        earliest_possible_date = datetime(year=2015,
                                          month=12,
                                          day=1,
                                          tzinfo=timezone.utc)
        latest_possible_date = datetime(year=2016,
                                        month=1,
                                        day=2,
                                        tzinfo=timezone.utc)
        earliest_date = data.value_date.min()
        latest_date = data.value_date.max()
        test.assertGreater(earliest_date, earliest_possible_date)
        test.assertLess(latest_date, latest_possible_date)

        for location_name, subset in data.groupby(by="observation_location"):
            test.assertGreater(subset.value_date.min(), earliest_possible_date)
            test.assertLess(subset.value_date.max(), latest_possible_date)

            current_date = earliest_date.date()
            present_days = subset.value_date.apply(lambda d: d.date()).unique()
            missing_days = list()

            while current_date <= latest_date:
                if current_date not in present_days:
                    missing_days.append(current_date)
                else:
                    missing_days.clear()

                test.assertLess(len(missing_days), 5)

                current_date += timedelta(days=1)
コード例 #8
0
def doframe(t: unittest.TestCase, curr: sllib.Frame, prev: sllib.Frame):
    """Validate some basic data for the frame"""
    t.assertGreaterEqual(curr.course, 0)
    t.assertLessEqual(curr.course, 6.28)
    t.assertLess(curr.gps_speed, 15)
    t.assertLess(curr.altitude, 500)
    t.assertLess(curr.temperature, 22)
    t.assertGreater(curr.temperature, 10)
    t.assertGreater(curr.framesize, curr.packetsize)
    t.assertGreater(curr.framesize, 1900)
    t.assertLessEqual(len(curr.packet), curr.packetsize)
    if prev is not None:
        t.assertGreater(curr.offset, prev.offset)
        t.assertGreaterEqual(curr.time1, prev.time1)
コード例 #9
0
ファイル: test.py プロジェクト: meihuisu/UCVM-reallyOld
def run_acceptance_test(test_case: unittest.TestCase,
                        model_id: str,
                        props_to_test: list = None) -> bool:
    """
    Runs the acceptance test for the given model id.
    :param test_case: The unittest case.
    :param model_id: The model ID to run the test for.
    :return: True if successful, false or exception if not.
    """
    npy_test_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id,
                                 "test_" + model_id + ".npy")
    ucvm_model_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id,
                                   "ucvm_model.xml")

    spacing = 0.05
    depth = 5000
    bottom_corner = {"e": 0, "n": 0}

    if not os.path.exists(npy_test_file) or not os.path.exists(
            ucvm_model_file):
        return False

    with open(ucvm_model_file, "r") as fd:
        ucvm_model = xmltodict.parse(fd.read())
        bottom_corner["e"] = \
            float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["e"])
        bottom_corner["n"] = \
            float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["n"])
        model_type = ucvm_model["root"]["information"]["type"]

    arr = np.load(npy_test_file)
    nums = {"x": len(arr), "y": len(arr[0]), "z": len(arr[0][0])}

    sd_array = [
        SeismicData() for _ in range(nums["x"] * nums["y"] * nums["z"])
    ]
    counter = 0

    for z in range(nums["z"]):
        for y in range(nums["y"]):
            for x in range(nums["x"]):
                sd_array[counter].original_point = Point(
                    bottom_corner["e"] + spacing * x,
                    bottom_corner["n"] + spacing * y, 0 + depth * z)
                counter += 1

    UCVM.query(sd_array, model_id, [model_type])

    if props_to_test is None or len(props_to_test) == 0:
        props_to_test = ["vp", "vs", "density"]

    counter = 0
    epsilon = 0.006
    for z in range(nums["z"]):
        for y in range(nums["y"]):
            for x in range(nums["x"]):
                if arr[x][y][z][0] <= 0 and sd_array[counter].velocity_properties.vp is None or \
                   arr[x][y][z][1] <= 0 and sd_array[counter].velocity_properties.vs is None or \
                   arr[x][y][z][2] <= 0 and sd_array[counter].velocity_properties.density is None:
                    counter += 1
                    continue

                # This is to account for a floating point rounding issue in the CVM-S4.26 test which has the new UCVM
                # thinking that the corner is in bounds and the old version thinking it's out of bounds. This version
                # thinks the point is 1534.999999999 where as the old version thinks it's exactly 1535. This also fixes
                # a difference whereby the old CVM-S5 extended below 50000km but the new one does not.
                if (sd_array[counter].original_point.x_value == -116 and
                    sd_array[counter].original_point.y_value == 30.45 and model_id == "cvms426") or \
                   (sd_array[counter].original_point.z_value == 50000 and model_id == "cvms426"):
                    counter += 1
                    continue

                if "vp" in props_to_test:
                    test_case.assertGreater(
                        sd_array[counter].velocity_properties.vp /
                        arr[x][y][z][0], 1 - epsilon)
                    test_case.assertLess(
                        sd_array[counter].velocity_properties.vp /
                        arr[x][y][z][0], 1 + epsilon)
                if "vs" in props_to_test:
                    test_case.assertGreater(
                        sd_array[counter].velocity_properties.vs /
                        arr[x][y][z][1], 1 - epsilon)
                    test_case.assertLess(
                        sd_array[counter].velocity_properties.vs /
                        arr[x][y][z][1], 1 + epsilon)
                if "density" in props_to_test:
                    test_case.assertGreater(
                        sd_array[counter].velocity_properties.density /
                        arr[x][y][z][2], 1 - epsilon)
                    test_case.assertLess(
                        sd_array[counter].velocity_properties.density /
                        arr[x][y][z][2], 1 + epsilon)
                counter += 1

    return True
コード例 #10
0
ファイル: test.py プロジェクト: SCECcode/UCVM
def run_acceptance_test(test_case: unittest.TestCase, model_id: str, props_to_test: list=None) -> bool:
    """
    Runs the acceptance test for the given model id.
    :param test_case: The unittest case.
    :param model_id: The model ID to run the test for.
    :return: True if successful, false or exception if not.
    """
    npy_test_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "test_" + model_id + ".npy")
    ucvm_model_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "ucvm_model.xml")

    spacing = 0.05
    depth = 5000
    bottom_corner = {
        "e": 0,
        "n": 0
    }

    if not os.path.exists(npy_test_file) or not os.path.exists(ucvm_model_file):
        return False

    with open(ucvm_model_file, "r") as fd:
        ucvm_model = xmltodict.parse(fd.read())
        bottom_corner["e"] = \
            float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["e"])
        bottom_corner["n"] = \
            float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["n"])
        model_type = ucvm_model["root"]["information"]["type"]

    arr = np.load(npy_test_file)
    nums = {
        "x": len(arr),
        "y": len(arr[0]),
        "z": len(arr[0][0])
    }

    sd_array = [SeismicData() for _ in range(nums["x"] * nums["y"] * nums["z"])]
    counter = 0

    for z in range(nums["z"]):
        for y in range(nums["y"]):
            for x in range(nums["x"]):
                sd_array[counter].original_point = Point(bottom_corner["e"] + spacing * x,
                                                         bottom_corner["n"] + spacing * y,
                                                         0 + depth * z)
                counter += 1

    UCVM.query(sd_array, model_id, [model_type])

    if props_to_test is None or len(props_to_test) == 0:
        props_to_test = ["vp", "vs", "density"]

    counter = 0
    epsilon = 0.006
    for z in range(nums["z"]):
        for y in range(nums["y"]):
            for x in range(nums["x"]):
                if arr[x][y][z][0] <= 0 and sd_array[counter].velocity_properties.vp is None or \
                   arr[x][y][z][1] <= 0 and sd_array[counter].velocity_properties.vs is None or \
                   arr[x][y][z][2] <= 0 and sd_array[counter].velocity_properties.density is None:
                    counter += 1
                    continue

                # This is to account for a floating point rounding issue in the CVM-S4.26 test which has the new UCVM
                # thinking that the corner is in bounds and the old version thinking it's out of bounds. This version
                # thinks the point is 1534.999999999 where as the old version thinks it's exactly 1535. This also fixes
                # a difference whereby the old CVM-S5 extended below 50000km but the new one does not.
                if (sd_array[counter].original_point.x_value == -116 and
                    sd_array[counter].original_point.y_value == 30.45 and model_id == "cvms426") or \
                   (sd_array[counter].original_point.z_value == 50000 and model_id == "cvms426"):
                    counter += 1
                    continue

                if "vp" in props_to_test:
                    test_case.assertGreater(sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 - epsilon)
                    test_case.assertLess(sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 + epsilon)
                if "vs" in props_to_test:
                    test_case.assertGreater(sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 - epsilon)
                    test_case.assertLess(sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 + epsilon)
                if "density" in props_to_test:
                    test_case.assertGreater(sd_array[counter].velocity_properties.density / arr[x][y][z][2],
                                            1 - epsilon)
                    test_case.assertLess(sd_array[counter].velocity_properties.density / arr[x][y][z][2], 1 + epsilon)
                counter += 1

    return True
コード例 #11
0
ファイル: value_assertion.py プロジェクト: emilkarlen/exactly
 def _apply(self, put: unittest.TestCase, value: T,
            message_builder: MessageBuilder):
     put.assertGreater(value, self.limit,
                       message_builder.apply(self.message))