当前位置: 首页>>代码示例>>Python>>正文


Python helpers.TestStore类代码示例

本文整理汇总了Python中tests.utils.helpers.TestStore的典型用法代码示例。如果您正苦于以下问题:Python TestStore类的具体用法?Python TestStore怎么用?Python TestStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestStore类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     self.mixin = self.create_job_with_mixin({'CALCULATION_MODE': 'Hazard'},
                                             opensha.ClassicalMixin)
     # Store the canned result data in the KVS.
     key = self.mixin.job_id
     for realization in xrange(2):
         key = "%s/%s" % (self.mixin.job_id, realization + 1)
         TestStore.put(key, self.mock_results[realization])
         self.keys.append(key)
     LOG.debug("keys = '%s'" % self.keys)
     # Initialize the mixin instance.
     self.mixin.params = dict(NUMBER_OF_LOGIC_TREE_SAMPLES=2,
                              WIDTH_OF_MFD_BIN=1)
     self.mixin.calc = self.FakeLogicTreeProcessor()
     self.mixin.cache = dict()
开发者ID:dsg101,项目名称:openquake,代码行数:15,代码来源:hazard_classical_unittest.py

示例2: test_map_serializer_called_when_configured

    def test_map_serializer_called_when_configured(self):
        """
        The quantile map serialization function is called when the
        POES parameter is specified in the configuration file.
        """
        def fake_serializer(*args):
            """Fake serialization function to be used in this test."""
            fake_serializer.number_of_calls += 1

        fake_serializer.number_of_calls = 0

        def fake_map_func(*args):
            return ["quantile_hazard_map!10!-122.9!38.0!0.2",
                    "quantile_hazard_map!10!-121.9!38.0!0.2",
                    "quantile_hazard_map!10!-122.8!38.0!0.4",
                    "quantile_hazard_map!10!-121.8!38.0!0.4"]

        key = TestStore.put(self.job_ctxt.job_id,
                            self.mock_results)
        self.keys.append(key)
        self.job_ctxt.params["POES"] = "0.6 0.8"
        self.calculator.do_quantiles(
            self.sites, 1, [0.2, 0.4],
            curve_serializer=lambda _, __: True,
            curve_task=test_data_reflector,
            map_func=fake_map_func,
            map_serializer=fake_serializer)
        # The serializer is called once for each quantile.
        self.assertEqual(2, fake_serializer.number_of_calls)
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:29,代码来源:hazard_classical_test.py

示例3: test_distribute_with_ignore_result_set

    def test_distribute_with_ignore_result_set(self):
        """
        The specified number of subtasks is actually spawned even for tasks
        with ignore_result=True and these run and complete.

        Since the results of the tasks are ignored, the only way to know that
        they ran and completed is to verify that the data they were supposed
        to write the key value store is actually there.
        """

        def value(key):
            """Construct a test value for the given key."""
            return key[-3:] * 2

        keys = ["irtc:%s" % str(uuid.uuid4())[:8] for _ in xrange(5)]
        values = [value(uid) for uid in keys]
        data = zip(keys, values)

        result = tasks.distribute(ignore_result, ("data", [[d] for d in data]))
        # An empty list is returned for tasks with ignore_result=True
        # and no asynchronous task handler function.
        self.assertEqual(False, bool(result))

        # Give the tasks a bit of time to complete.
        time.sleep(0.1)

        for key, value in data:
            self.assertEqual(value, TestStore.get(key))
开发者ID:ROB-Seismology,项目名称:oq-engine,代码行数:28,代码来源:utils_tasks_test.py

示例4: ath

 def ath(data):
     """
     An asynchronous task handler function that converts all task
     results to upper case and returns the list of keys found.
     """
     items_expected = len(data)
     items_found = []
     while len(items_found) < items_expected:
         for key, _ in data:
             if key in items_found:
                 continue
             value = TestStore.get(key)
             if value is not None:
                 TestStore.set(key, value.upper())
                 items_found.append(key)
         time.sleep(0.05)
     return items_found
开发者ID:ROB-Seismology,项目名称:oq-engine,代码行数:17,代码来源:utils_tasks_test.py

示例5: setUp

    def setUp(self):
        params = dict(
            CALCULATION_MODE='Hazard',
            SOURCE_MODEL_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_SRC_MODEL_LT,
            GMPE_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_GMPE_LT,
            BASE_PATH=SIMPLE_FAULT_BASE_PATH, OUTPUT_DIR="output",
            NUMBER_OF_LOGIC_TREE_SAMPLES=2, WIDTH_OF_MFD_BIN=1)

        self.job_ctxt = create_job(params, job_id=99)
        self.calculator = classical.ClassicalHazardCalculator(self.job_ctxt)

        # Store the canned result data in the KVS.
        key = self.job_ctxt.job_id
        for realization in xrange(2):
            key = "%s/%s" % (self.job_ctxt.job_id, realization + 1)
            TestStore.put(key, self.mock_results[realization])
            self.keys.append(key)
        LOG.debug("keys = '%s'" % self.keys)

        self.calculator.calc = self.FakeLogicTreeProcessor()
        self.calculator.cache = dict()
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:21,代码来源:hazard_classical_test.py

示例6: test_curve_serializer_called_when_passed

    def test_curve_serializer_called_when_passed(self):
        """The passed quantile curve serialization function is called."""

        def fake_serializer(**kwargs):
            """Fake serialization function to be used in this test."""
            fake_serializer.number_of_calls += 1

        fake_serializer.number_of_calls = 0

        key = TestStore.put(self.job_ctxt.job_id, self.mock_results)
        self.keys.append(key)
        self.calculator.do_quantiles(
            self.sites, 1, [0.2, 0.4], curve_serializer=fake_serializer,
            curve_task=test_async_data_reflector)
        # The serializer is called only once (for all quantiles).
        self.assertEqual(1, fake_serializer.number_of_calls)
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:16,代码来源:hazard_classical_test.py

示例7: test_missing_map_serializer_assertion

    def test_missing_map_serializer_assertion(self):
        """
        When the quantile map serialization function is not set an
        `AssertionError` is raised.

        TODO: once everyone is on python rev. > 2.7 extend the test to check
        for the specific assertion message.
        """

        key = TestStore.put(self.job_ctxt.job_id, self.mock_results)
        self.keys.append(key)
        self.job_ctxt.params["POES"] = "0.6 0.8"
        self.assertRaises(
            AssertionError, self.calculator.do_quantiles,
            self.sites, 1, [0.5],
            curve_serializer=lambda _, __: True,
            curve_task=test_data_reflector, map_func=lambda _: [1, 2, 3])
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:17,代码来源:hazard_classical_test.py

示例8: test_missing_map_function_assertion

    def test_missing_map_function_assertion(self):
        """
        When the mean map calculation function is not set an `AssertionError`
        is raised.

        TODO: once everyone is on python rev. > 2.7 extend the test to check
        for the specific assertion message.
        """

        key = TestStore.put(self.mixin.job_id, self.mock_results)
        self.keys.append(key)
        self.mixin.params["POES"] = "0.6 0.8"
        self.assertRaises(
            AssertionError, self.mixin.do_means,
            self.sites, 1,
            curve_serializer=lambda _: True, curve_task=test_data_reflector,
            map_serializer=lambda _: True, map_func=None)
开发者ID:dsg101,项目名称:openquake,代码行数:17,代码来源:hazard_classical_unittest.py

示例9: test_map_serializer_not_called_unless_configured

    def test_map_serializer_not_called_unless_configured(self):
        """
        The mean map serialization function is not called unless the
        POES parameter was specified in the configuration file.
        """

        def fake_serializer(kvs_keys):
            """Fake serialization function to be used in this test."""
            # Check that the data returned is the one we expect for the current
            # realization.
            fake_serializer.number_of_calls += 1

        fake_serializer.number_of_calls = 0

        key = TestStore.put(self.job_ctxt.job_id, self.mock_results)
        self.keys.append(key)
        self.calculator.do_means(self.sites, 1,
                        curve_serializer=lambda _: True,
                        curve_task=test_data_reflector)
        self.assertEqual(0, fake_serializer.number_of_calls)
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:20,代码来源:hazard_classical_test.py

示例10: test_distribute_with_ignore_result_set_and_ath

    def test_distribute_with_ignore_result_set_and_ath(self):
        """
        The specified number of subtasks is actually spawned (even for tasks
        with ignore_result=True) and the asynchronous task handler function is
        run.
        """

        def value(key):
            """Construct a test value for the given key."""
            return key[-3:] * 2

        def ath(data):
            """
            An asynchronous task handler function that converts all task
            results to upper case and returns the list of keys found.
            """
            items_expected = len(data)
            items_found = []
            while len(items_found) < items_expected:
                for key, _ in data:
                    if key in items_found:
                        continue
                    value = TestStore.get(key)
                    if value is not None:
                        TestStore.set(key, value.upper())
                        items_found.append(key)
                time.sleep(0.05)
            return items_found

        keys = ["irtc:%s" % str(uuid.uuid4())[:8] for _ in xrange(5)]
        values = [value(uid) for uid in keys]
        data = zip(keys, values)

        args = ("data", [[d] for d in data])
        result = tasks.distribute(ignore_result, args, ath=ath,
                                  ath_args=dict(data=data))
        self.assertEqual(sorted(keys), sorted(result))

        for key, value in data:
            self.assertEqual(value.upper(), TestStore.get(key))
开发者ID:ROB-Seismology,项目名称:oq-engine,代码行数:40,代码来源:utils_tasks_test.py

示例11: tearDown

 def tearDown(self):
     # Remove the canned result data from the KVS.
     for key in self.keys:
         TestStore.remove(key)
开发者ID:PseudononymousEpistle,项目名称:oq-engine,代码行数:4,代码来源:hazard_classical_test.py

示例12: setUp

 def setUp(self):
     # Make sure we have no obsolete test data in the kvs.
     kvs = TestStore.kvs()
     existing_data = kvs.keys("irtc:*")
     if existing_data:
         kvs.delete(*existing_data)
开发者ID:ROB-Seismology,项目名称:oq-engine,代码行数:6,代码来源:utils_tasks_test.py


注:本文中的tests.utils.helpers.TestStore类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。