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


Python Experiment.find_or_create方法代码示例

本文整理汇总了Python中sixpack.models.Experiment.find_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.find_or_create方法的具体用法?Python Experiment.find_or_create怎么用?Python Experiment.find_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sixpack.models.Experiment的用法示例。


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

示例1: test_differing_alternatives_fails

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_differing_alternatives_fails(self):
        exp = Experiment.find_or_create("load-differing-alts", ["yes", "zack", "PBR"], self.redis)
        alts = Experiment.load_alternatives(exp.name, self.redis)
        self.assertEqual(sorted(alts), sorted(["PBR", "yes", "zack"]))

        with self.assertRaises(ValueError):
            exp = Experiment.find_or_create("load-differing-alts", ["kyle", "zack", "PBR"], self.redis)
开发者ID:spil-bahadir,项目名称:sixpack,代码行数:9,代码来源:experiment_model_test.py

示例2: test_differing_alternatives_fails

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_differing_alternatives_fails(self):
        exp = Experiment.find_or_create('load-differing-alts', ['yes', 'zack', 'PBR'], redis=self.redis)
        alts = Experiment.load_alternatives(exp.name, redis=self.redis)
        self.assertEqual(sorted(alts), sorted(['PBR', 'yes', 'zack']))

        with self.assertRaises(ValueError):
            exp = Experiment.find_or_create('load-differing-alts', ['kyle', 'zack', 'PBR'], redis=self.redis)
开发者ID:VPilitsyn,项目名称:sixpack,代码行数:9,代码来源:experiment_model_test.py

示例3: test_valid_traffic_fractions_save

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_valid_traffic_fractions_save(self):
        # test the hidden prop gets set
        exp = Experiment.find_or_create('dist-02', ['dist', '100'], traffic_fraction=0.02, redis=self.redis)
        self.assertEqual(exp._traffic_fraction, 0.02)

        exp = Experiment.find_or_create('dist-100', ['dist', '100'], traffic_fraction=0.4, redis=self.redis)
        self.assertEqual(exp._traffic_fraction, 0.40)
开发者ID:VPilitsyn,项目名称:sixpack,代码行数:9,代码来源:experiment_model_test.py

示例4: test_change_alternatives

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_change_alternatives(self):
        exp = Experiment.find_or_create("never-gonna-x", ["let", "you", "down"], self.redis)

        with self.assertRaises(ValueError):
            Experiment.find_or_create("never-gonna-x", ["let", "you", "down", "give", "you", "up"], self.redis)

        exp.delete()

        Experiment.find_or_create("never-gonna-x", ["let", "you", "down", "give", "you", "up"], self.redis)
开发者ID:spil-bahadir,项目名称:sixpack,代码行数:11,代码来源:experiment_model_test.py

示例5: test_valid_traffic_fractions_save

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_valid_traffic_fractions_save(self):
        # test the hidden prop gets set
        opts = {'traffic_fraction': 0.02}
        exp = Experiment.find_or_create('dist-02', ['dist', '100'], self.redis, opts)
        self.assertEqual(exp._traffic_fraction, 0.02)

        opts = {'traffic_fraction': 0.4}
        exp = Experiment.find_or_create('dist-100', ['dist', '100'], self.redis, opts)
        self.assertEqual(exp._traffic_fraction, 0.40)
开发者ID:metricle,项目名称:sixpack,代码行数:11,代码来源:experiment_model_test.py

示例6: test_change_alternatives

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_change_alternatives(self):
        exp = Experiment.find_or_create('never-gonna-x', ['let', 'you', 'down'], redis=self.redis)

        with self.assertRaises(ValueError):
            Experiment.find_or_create('never-gonna-x', ['let', 'you', 'down', 'give', 'you', 'up'], redis=self.redis)

        exp.delete()

        Experiment.find_or_create('never-gonna-x', ['let', 'you', 'down', 'give', 'you', 'up'], redis=self.redis)
开发者ID:VPilitsyn,项目名称:sixpack,代码行数:11,代码来源:experiment_model_test.py

示例7: test_find_or_create

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_find_or_create(self):
        # should throw a ValueError if alters are invalid
        with self.assertRaises(ValueError):
            Experiment.find_or_create("party-time", ["1"], self.redis)

        with self.assertRaises(ValueError):
            Experiment.find_or_create("party-time", ["1", "*****"], self.redis)

        # should create a -NEW- experiment if experiment has never been used
        with self.assertRaises(ValueError):
            Experiment.find("dance-dance", self.redis)
开发者ID:spil-bahadir,项目名称:sixpack,代码行数:13,代码来源:experiment_model_test.py

示例8: test_find_or_create

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_find_or_create(self):
        # should throw a ValueError if alters are invalid
        with self.assertRaises(ValueError):
            Experiment.find_or_create('party-time', ['1'], redis=self.redis)

        with self.assertRaises(ValueError):
            Experiment.find_or_create('party-time', ['1', '*****'], redis=self.redis)

        # should create a -NEW- experiment if experiment has never been used
        with self.assertRaises(ValueError):
            Experiment.find('dance-dance', redis=self.redis)
开发者ID:VPilitsyn,项目名称:sixpack,代码行数:13,代码来源:experiment_model_test.py

示例9: test_excluded_client

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_excluded_client(self):
        # need proper redis to register the msetbit script
        import sixpack.db
        sixpack.db.REDIS.flushall()
        e = Experiment.find_or_create('excluded-client', ['option-a', 'option-b'], redis=sixpack.db.REDIS)
        self.assertEqual(e.control.participant_count(), 0)
        self.assertEqual(e.control.completed_count(), 0)

        # force participate 1 proper client on the control alternative
        cnil = Client("cnil", redis=sixpack.db.REDIS)
        e.control.record_participation(cnil)
        e.convert(cnil)

        # exclude client, gets control alternative & try to convert
        c = Client("c", redis=sixpack.db.REDIS)
        e.exclude_client(c)

        self.assertTrue(e.control == e.get_alternative(c))
        self.assertTrue(None == e.existing_alternative(c))
        with self.assertRaises(ValueError):
            e.convert(c)

        # participation & completed count should be 1
        self.assertEqual(e.control.participant_count(), 1)
        self.assertEqual(e.control.completed_count(), 1)
开发者ID:nickveenhof,项目名称:sixpack,代码行数:27,代码来源:experiment_model_test.py

示例10: test_set_kpi

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_set_kpi(self):
        exp = Experiment.find_or_create('multi-kpi', ['kpi', '123'], redis=self.redis)
        # We shouldn't beable to manually set a KPI. Only via web request
        with self.assertRaises(ValueError):
            exp.set_kpi('bananza')

        # simulate conversion via webrequest
        client = Client(100, redis=self.redis)

        exp.get_alternative(client)
        exp.convert(client, None, 'bananza')

        exp2 = Experiment.find_or_create('multi-kpi', ['kpi', '123'], redis=self.redis)
        self.assertEqual(exp2.kpi, None)
        exp2.set_kpi('bananza')
        self.assertEqual(exp2.kpi, 'bananza')
开发者ID:nickveenhof,项目名称:sixpack,代码行数:18,代码来源:experiment_model_test.py

示例11: test_get_alternative

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_get_alternative(self):
        client = Client(10, redis=self.redis)

        exp = Experiment.find_or_create('pause-control', ['w', 'l'], redis=self.redis)
        exp.pause()

        # should return control on paused test with no winner
        alt = exp.get_alternative(client)
        self.assertEqual(alt.name, 'w')

        # should return current participation
        exp.resume()

        # should be one or the other.
        # @todo, this test is not really testing anything.
        selected_for_client = exp.get_alternative(client)
        self.assertIn(selected_for_client.name, ['w', 'l'])

        # should check to see if client is participating and only return the same alt
        # unsure how to currently test since fakeredis obviously doesn't parse lua
        # most likely integration tests
        exp.archive()

        # test if the redis key is no longer present
        self.redis.get(_key('e:{0}:users'.format(exp.name)))

        # should return control on archived test
        alt = exp.get_alternative(client)
        self.assertEqual(alt.name, 'w')
开发者ID:desaraev,项目名称:sixpack,代码行数:31,代码来源:experiment_model_test.py

示例12: test_add_kpi

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_add_kpi(self):
        exp = Experiment.find_or_create('multi-kpi-add', ['asdf', '999'], redis=self.redis)
        kpi = 'omg-pop'

        exp.add_kpi(kpi)
        key = "{0}:kpis".format(exp.key(include_kpi=False))
        self.assertIn(kpi, self.redis.smembers(key))
        exp.delete()
开发者ID:VPilitsyn,项目名称:sixpack,代码行数:10,代码来源:experiment_model_test.py

示例13: test_winner_saves_to_db

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_winner_saves_to_db(self):
        e = Experiment.find_or_create('winner-saves-to-db', ['one', 'two'], redis=self.app.redis)
        client = SClient('random', redis=self.app.redis)

        e.set_winner('two')
        self.assertEqual('two', e.get_alternative(client).name)
        e.set_winner('one')
        self.assertEqual('two', e.get_alternative(client).name)
开发者ID:harmoney-dev,项目名称:sixpack,代码行数:10,代码来源:alternative_choice_test.py

示例14: test_add_kpi

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_add_kpi(self):
        exp = Experiment.find_or_create("multi-kpi-add", ["asdf", "999"], self.redis)
        kpi = "omg-pop"

        exp.add_kpi(kpi)
        key = "{0}:kpis".format(exp.key(include_kpi=False))
        self.assertIn(kpi, self.redis.smembers(key))
        exp.delete()
开发者ID:spil-bahadir,项目名称:sixpack,代码行数:10,代码来源:experiment_model_test.py

示例15: test_excluded_clients

# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import find_or_create [as 别名]
    def test_excluded_clients(self):
        e = Experiment.find_or_create('count-excluded-clients', ['red', 'blue'], redis=self.redis)

        for i in range(10):
            c = Client("c-%d" % i, self.redis)
            e.exclude_client(c)

            # there is a very small chance that a client was not excluded.
            self.assertEqual(e.excluded_clients(), i + 1)
开发者ID:nickveenhof,项目名称:sixpack,代码行数:11,代码来源:experiment_model_test.py


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