本文整理汇总了Python中flask_split.models.Experiment类的典型用法代码示例。如果您正苦于以下问题:Python Experiment类的具体用法?Python Experiment怎么用?Python Experiment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Experiment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finished_clears_out_users_participation_from_their_session
def test_finished_clears_out_users_participation_from_their_session(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
assert session['split'] == {"link_color": alternative_name}
finished('link_color')
assert session['split'] == {}
示例2: test_know_if_it_is_the_control_of_an_experiment
def test_know_if_it_is_the_control_of_an_experiment(self):
experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
experiment.save()
alternative = Alternative(self.redis, 'Basket', 'basket_text')
assert alternative.is_control
alternative = Alternative(self.redis, 'Cart', 'basket_text')
assert not alternative.is_control
示例3: test_increment_completed_count
def test_increment_completed_count(self):
experiment = Experiment(self.redis, 'basket_text', 'Basket', "Cart")
experiment.save()
alternative = Alternative(self.redis, 'Basket', 'basket_text')
old_completed_count = alternative.participant_count
alternative.increment_completion()
assert alternative.completed_count == old_completed_count + 1
示例4: test_saves_the_start_time_to_redis
def test_saves_the_start_time_to_redis(self):
experiment_start_time = datetime(2012, 3, 9, 22, 01, 34)
(flexmock(Experiment)
.should_receive('_get_time')
.and_return(experiment_start_time))
experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
experiment.save()
assert experiment.start_time == experiment_start_time
示例5: test_allow_you_to_specify_a_winner
def test_allow_you_to_specify_a_winner(self):
experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'red')
experiment.winner = 'red'
experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'red')
assert experiment.winner.name == 'red'
示例6: test_finished_increments_completed_alternative_counter
def test_finished_increments_completed_alternative_counter(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
alternative = Alternative(self.redis, alternative_name, 'link_color')
previous_completion_count = alternative.completed_count
finished('link_color')
new_completion_count = alternative.completed_count
assert new_completion_count == previous_completion_count + 1
示例7: test_displays_the_start_date
def test_displays_the_start_date(self):
experiment_start_time = datetime(2011, 7, 7)
(flexmock(Experiment)
.should_receive('_get_time')
.and_return(experiment_start_time))
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
response = self.client.get('/split/')
assert '2011-07-07' in response.data
示例8: test_conversions_return_conversion_rates_for_alternatives
def test_conversions_return_conversion_rates_for_alternatives(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
alternative = Alternative(self.redis, alternative_name, 'link_color')
assert alternative.conversion_rate == 0.0
finished('link_color')
assert alternative.conversion_rate == 1.0
示例9: test_finished_dont_clear_out_the_users_session_if_reset_is_false
def test_finished_dont_clear_out_the_users_session_if_reset_is_false(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
assert session['split'] == {"link_color": alternative_name}
finished('link_color', reset=False)
assert session['split'] == {
"link_color": alternative_name,
}
assert session['split_finished'] == set(['link_color'])
示例10: test_finished_dont_incr_completed_twice_if_no_reset
def test_finished_dont_incr_completed_twice_if_no_reset(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
finished('link_color', reset=False)
finished('link_color', reset=False)
alternative = Alternative(self.redis, alternative_name, 'link_color')
completion_count = alternative.completed_count
assert completion_count == 1
示例11: test_handles_not_having_a_start_time
def test_handles_not_having_a_start_time(self):
experiment_start_time = datetime(2012, 3, 9, 22, 01, 34)
(flexmock(Experiment)
.should_receive('_get_time')
.and_return(experiment_start_time))
experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
experiment.save()
self.redis.hdel('experiment_start_times', experiment.name)
assert experiment.start_time is None
示例12: test_next_alternative_always_returns_the_winner_if_one_exists
def test_next_alternative_always_returns_the_winner_if_one_exists(self):
experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'red', 'green')
green = Alternative(self.redis, 'green', 'link_color')
experiment.winner = 'green'
assert experiment.next_alternative().name == 'green'
green.increment_participation()
experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'red', 'green')
assert experiment.next_alternative().name == 'green'
示例13: test_reset_an_experiment
def test_reset_an_experiment(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
red = Alternative(self.redis, 'red', 'link_color')
blue = Alternative(self.redis, 'blue', 'link_color')
red.participant_count = 5
blue.participant_count = 6
response = self.client.post('/split/link_color/reset')
assert_redirects(response, '/split/')
assert red.participant_count == 0
assert blue.participant_count == 0
示例14: test_reset_an_experiment_if_loaded_with_different_alternatives
def test_reset_an_experiment_if_loaded_with_different_alternatives(self):
experiment = Experiment(
self.redis, 'link_color', 'blue', 'red', 'green')
experiment.save()
blue = Alternative(self.redis, 'blue', 'link_color')
blue.participant_count = 5
blue.save()
same_experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'yellow', 'orange')
alternative_names = [a.name for a in same_experiment.alternatives]
assert alternative_names == ['blue', 'yellow', 'orange']
new_blue = Alternative(self.redis, 'blue', 'link_color')
assert new_blue.participant_count == 0
示例15: test_ab_test_increments_participation_counter_for_new_user
def test_ab_test_increments_participation_counter_for_new_user(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
red = Alternative(self.redis, 'red', 'link_color')
blue = Alternative(self.redis, 'blue', 'link_color')
previous_red_count = red.participant_count
previous_blue_count = blue.participant_count
ab_test('link_color', 'blue', 'red')
new_red_count = red.participant_count
new_blue_count = blue.participant_count
assert (new_red_count + new_blue_count ==
previous_red_count + previous_blue_count + 1)