本文整理汇总了Python中sixpack.models.Experiment.save方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.save方法的具体用法?Python Experiment.save怎么用?Python Experiment.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sixpack.models.Experiment
的用法示例。
在下文中一共展示了Experiment.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_created_at
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
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))
示例2: test_delete
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_delete(self):
exp = Experiment('delete-me', self.alternatives, redis=self.redis)
exp.save()
exp.delete()
with self.assertRaises(ValueError):
Experiment.find('delete-me', redis=self.redis)
示例3: test_is_control
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
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()
示例4: test_created_at
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
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))
示例5: test_reset_winner
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_reset_winner(self):
exp = Experiment("show-something-reset-winner", self.alternatives, self.redis)
exp.save()
exp.set_winner("yes")
self.assertTrue(exp.winner is not None)
self.assertEqual(exp.winner, "yes")
exp.reset_winner()
self.assertIsNone(exp.winner)
示例6: test_reset_winner
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_reset_winner(self):
exp = Experiment('show-something-reset-winner', self.alternatives, redis=self.redis)
exp.save()
exp.set_winner('yes')
self.assertTrue(exp.winner is not None)
self.assertEqual(exp.winner.name, 'yes')
exp.reset_winner()
self.assertIsNone(exp.winner)
示例7: test_leaky_delete
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_leaky_delete(self):
exp = Experiment('delete-me-1', self.alternatives, redis=self.redis)
exp.save()
exp2 = Experiment('delete', self.alternatives, redis=self.redis)
exp2.save()
exp2.delete()
exp3 = Experiment.find('delete-me-1', redis=self.redis)
self.assertEqual(exp3.get_alternative_names(), self.alternatives)
示例8: test_find
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_find(self):
exp = Experiment('crunches-situps', ['crunches', 'situps'], redis=self.redis)
exp.save()
with self.assertRaises(ValueError):
Experiment.find('this-does-not-exist', redis=self.redis)
try:
Experiment.find('crunches-situps', redis=self.redis)
except:
self.fail('known exp not found')
示例9: test_find
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_find(self):
exp = Experiment("crunches-situps", ["crunches", "situps"], self.redis)
exp.save()
with self.assertRaises(ValueError):
Experiment.find("this-does-not-exist", self.redis)
try:
Experiment.find("crunches-situps", self.redis)
except:
self.fail("known exp not found")
示例10: test_save_with_conflict_persists_traffic_fraction
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_save_with_conflict_persists_traffic_fraction(self):
def fake_pipeline(transaction=True):
return FakePipelineRaisesWatchError(self.redis, transaction)
real_pipeline = self.redis.pipeline
self.redis.pipeline = fake_pipeline
# this experiment encounters a WatchError upon saving and only
# persists its traffic_fraction...
exp = Experiment('experiment', self.alternatives, redis=self.redis)
exp.set_traffic_fraction(0.5)
exp.save()
self.redis.pipeline = real_pipeline
# ...and a later instance can recover that traffic fraction
same_exp = Experiment('experiment', self.alternatives, redis=self.redis)
self.assertEqual(same_exp.traffic_fraction, 0.5)
示例11: test_all
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_all(self):
# there are three created in setUp()
all_of_them = Experiment.all(redis=self.redis)
self.assertEqual(len(all_of_them), 3)
exp_1 = Experiment('archive-this', ['archived', 'archived2'], redis=self.redis)
exp_1.save()
# Check if we have 4 active experiments in total
all_again = Experiment.all(redis=self.redis)
self.assertEqual(len(all_again), 4)
# Pause one experiment.
exp_1.pause()
# We should have 1 paused experiment in total
all_paused = Experiment.paused(redis=self.redis)
self.assertEqual(len(all_paused), 1)
# We should have 3 active experiments.
all_active_experiments = Experiment.all(redis=self.redis)
self.assertEqual(len(all_active_experiments), 3)
# Total, with paused and excluding archived should be 4.
all_with_paused = Experiment.all(exclude_paused=False, redis=self.redis)
self.assertEqual(len(all_with_paused), 4)
# Resume the experiment
exp_1.resume()
# We should have 4 active experiments
all_active_experiments = Experiment.all(redis=self.redis)
self.assertEqual(len(all_active_experiments), 4)
# Archive the experiment
exp_1.archive()
all_active_experiments = Experiment.all(redis=self.redis)
self.assertEqual(len(all_active_experiments), 3)
# We should have 1 archived experiment
all_archived = Experiment.archived(redis=self.redis)
self.assertEqual(len(all_archived), 1)
# Total, with archived, excluding paused should be 4
all_with_archived = Experiment.all(exclude_archived=False, redis=self.redis)
self.assertEqual(len(all_with_archived), 4)
示例12: test_all
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_all(self):
# there are three created in setUp()
all_of_them = Experiment.all(redis=self.redis)
self.assertEqual(len(all_of_them), 3)
exp_1 = Experiment('archive-this', ['archived', 'unarchive'], redis=self.redis)
exp_1.save()
all_again = Experiment.all(redis=self.redis)
self.assertEqual(len(all_again), 4)
exp_1.archive()
all_archived = Experiment.all(redis=self.redis)
self.assertEqual(len(all_archived), 3)
all_with_archived = Experiment.all(exclude_archived=False, redis=self.redis)
self.assertEqual(len(all_with_archived), 4)
all_archived = Experiment.archived(redis=self.redis)
self.assertEqual(len(all_archived), 1)
示例13: test_all
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_all(self):
# there are three created in setUp()
all_of_them = Experiment.all(self.redis)
self.assertEqual(len(all_of_them), 3)
exp_1 = Experiment("archive-this", ["archived", "unarchive"], self.redis)
exp_1.save()
all_again = Experiment.all(self.redis)
self.assertEqual(len(all_again), 4)
exp_1.archive()
all_archived = Experiment.all(self.redis)
self.assertEqual(len(all_archived), 3)
all_with_archived = Experiment.all(self.redis, False)
self.assertEqual(len(all_with_archived), 4)
all_archived = Experiment.archived(self.redis)
self.assertEqual(len(all_archived), 1)
示例14: TestExperimentModel
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
class TestExperimentModel(unittest.TestCase):
unit = True
def setUp(self):
self.redis = fakeredis.FakeStrictRedis()
self.alternatives = ['yes', 'no']
self.exp_1 = Experiment('show-something-awesome', self.alternatives, redis=self.redis)
self.exp_2 = Experiment('dales-lagunitas', ['dales', 'lagunitas'], redis=self.redis)
self.exp_3 = Experiment('mgd-budheavy', ['mgd', 'bud-heavy'], redis=self.redis)
self.exp_1.save()
self.exp_2.save()
self.exp_3.save()
def tearDown(self):
pipe = self.redis.pipeline()
pipe.flushdb()
pipe.execute()
def test_constructor(self):
with self.assertRaises(ValueError):
Experiment('not-enough-args', ['1'], redis=self.redis)
def test_save(self):
pass
def test_control(self):
control = self.exp_1.control
self.assertEqual(control.name, 'yes')
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, str))
def test_get_alternative_names(self):
exp = Experiment('show-something', self.alternatives, redis=self.redis)
names = exp.get_alternative_names()
self.assertEqual(sorted(self.alternatives), sorted(names))
def test_is_new_record(self):
exp = Experiment('show-something-is-new-record', self.alternatives, redis=self.redis)
self.assertTrue(exp.is_new_record())
exp.save()
self.assertFalse(exp.is_new_record())
# fakeredis does not currently support bitcount
# todo, fix fakeredis and
def _test_total_participants(self):
pass
def _test_total_conversions(self):
pass
def test_description(self):
exp = Experiment.find_or_create('never-gonna', ['give', 'you', 'up'], redis=self.redis)
self.assertEqual(exp.description, None)
exp.update_description('hallo')
self.assertEqual(exp.description, 'hallo')
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)
def test_delete(self):
exp = Experiment('delete-me', self.alternatives, redis=self.redis)
exp.save()
exp.delete()
with self.assertRaises(ValueError):
Experiment.find('delete-me', redis=self.redis)
def test_leaky_delete(self):
exp = Experiment('delete-me-1', self.alternatives, redis=self.redis)
exp.save()
exp2 = Experiment('delete', self.alternatives, redis=self.redis)
exp2.save()
exp2.delete()
exp3 = Experiment.find('delete-me-1', redis=self.redis)
self.assertEqual(exp3.get_alternative_names(), self.alternatives)
def test_archive(self):
self.assertFalse(self.exp_1.is_archived())
self.exp_1.archive()
self.assertTrue(self.exp_1.is_archived())
self.exp_1.unarchive()
self.assertFalse(self.exp_1.is_archived())
#.........这里部分代码省略.........
示例15: test_is_new_record
# 需要导入模块: from sixpack.models import Experiment [as 别名]
# 或者: from sixpack.models.Experiment import save [as 别名]
def test_is_new_record(self):
exp = Experiment('show-something-is-new-record', self.alternatives, redis=self.redis)
self.assertTrue(exp.is_new_record())
exp.save()
self.assertFalse(exp.is_new_record())