本文整理汇总了Python中sixpack.models.Experiment类的典型用法代码示例。如果您正苦于以下问题:Python Experiment类的具体用法?Python Experiment怎么用?Python Experiment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Experiment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_created_at
def test_created_at(self):
exp = Experiment("bench-press", ["joe", "think"], self.redis)
date = exp.created_at()
self.assertIsNone(date)
exp.save()
date = exp.created_at()
self.assertTrue(isinstance(date, datetime))
示例2: test_differing_alternatives_fails
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)
示例3: test_valid_traffic_fractions_save
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)
示例4: test_invalid_kpi
def test_invalid_kpi(self):
ret = Experiment.validate_kpi("!hello-jose")
self.assertFalse(ret)
ret = Experiment.validate_kpi("thunder storm")
self.assertFalse(ret)
ret = Experiment.validate_kpi("&!&&!&")
self.assertFalse(ret)
示例5: test_created_at
def test_created_at(self):
exp = Experiment('bench-press', ['joe', 'think'], redis=self.redis)
date = exp.created_at
self.assertIsNone(date)
exp.save()
date = exp.created_at
self.assertTrue(isinstance(date, datetime))
示例6: test_participate
def test_participate(self, mock_find_or_create):
exp = Experiment("test", ["no", "yes"], winner=None)
exp.get_alternative = Mock(return_value=Alternative("yes", exp))
mock_find_or_create.return_value = exp
alternative = participate("test", ["no", "yes"], "id1")
self.assertEqual("yes", alternative.name)
self.assertEqual("test", alternative.experiment.name)
示例7: test_differing_alternatives_fails
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)
示例8: test_participate_with_client_chosen_alternative
def test_participate_with_client_chosen_alternative(self, mock_find_or_create):
exp = Experiment("test", ["no", "yes"], winner=None)
exp.get_alternative = Mock(return_value=Alternative("yes", exp))
mock_find_or_create.return_value = exp
alternative = participate("test", ["no", "yes"], "id1", alternative="yes")
exp.get_alternative.assert_called_once()
self.assertEqual("yes", alternative.name)
示例9: test_set_winner
def test_set_winner(self):
exp = Experiment("test-winner", ["1", "2"], self.redis)
exp.set_winner("1")
self.assertTrue(exp.winner is not None)
exp.set_winner("1")
self.assertEqual(exp.winner, "1")
示例10: test_convert
def test_convert(self, mock_find):
exp = Experiment("test", ["no", "yes"], winner=None)
exp.convert = Mock(return_value=Alternative("yes", exp))
mock_find.return_value = exp
alternative = convert("test", "id1")
self.assertEqual("yes", alternative.name)
self.assertEqual("test", alternative.experiment.name)
示例11: test_set_winner
def test_set_winner(self):
exp = Experiment('test-winner', ['1', '2'], redis=self.redis)
exp.set_winner('1')
self.assertTrue(exp.winner is not None)
exp.set_winner('1')
self.assertEqual(exp.winner.name, '1')
示例12: test_is_control
def test_is_control(self):
exp = Experiment("trololo", ["yes", "no"], redis=self.redis)
exp.save()
alt = Alternative("yes", exp, redis=self.redis)
self.assertTrue(alt.is_control())
exp.delete()
示例13: test_convert_with_kpi
def test_convert_with_kpi(self, mock_find):
exp = Experiment("test", ["no", "yes"], winner=None)
exp.convert = Mock(return_value=Alternative("yes", exp))
mock_find.return_value = exp
alternative = convert("test", "id1", kpi="goal1")
# TODO: we're not really asserting anything about the KPI
self.assertEqual("yes", alternative.name)
self.assertEqual("test", alternative.experiment.name)
示例14: test_change_alternatives
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)
示例15: test_valid_traffic_fractions_save
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)