Пример #1
0
 def test_store_sample_mock_random(self, mock_random):
     key = KeyFactory(store_sample_locate=50)
     mock_random.return_value = 0.1
     assert key.store_sample("locate") is True
     mock_random.return_value = 0.5
     assert key.store_sample("locate") is True
     mock_random.return_value = 0.51
     assert key.store_sample("locate") is False
     mock_random.return_value = 0.9
     assert key.store_sample("locate") is False
Пример #2
0
 def test_store_sample_mock_random_with_global_rate(
     self, mock_random, global_rate, q1, q2, q3, q4
 ):
     assert 0.0 < (q3 - q2) < 0.1
     key = KeyFactory(store_sample_locate=50)
     mock_random.return_value = q1
     assert key.store_sample("locate", global_rate) is True
     mock_random.return_value = q2
     assert key.store_sample("locate", global_rate) is True
     mock_random.return_value = q3
     assert key.store_sample("locate", global_rate) is False
     mock_random.return_value = q4
     assert key.store_sample("locate", global_rate) is False
    def test_store_sample(self):
        key = KeyFactory(store_sample_locate=None, store_sample_submit=None)
        assert key.store_sample('locate') is False
        assert key.store_sample('submit') is False
        assert key.store_sample('region') is False

        key = KeyFactory(store_sample_locate=0, store_sample_submit=100)
        assert key.store_sample('locate') is False
        assert key.store_sample('submit') is True

        key = KeyFactory(store_sample_locate=50)
        results = []
        for i in range(20):
            results.append(key.store_sample('locate'))
        assert True in results
        assert False in results
Пример #4
0
    def test_store_sample(self):
        key = KeyFactory(store_sample_locate=None, store_sample_submit=None)
        assert key.store_sample('locate') is False
        assert key.store_sample('submit') is False
        assert key.store_sample('region') is False

        key = KeyFactory(store_sample_locate=0, store_sample_submit=100)
        assert key.store_sample('locate') is False
        assert key.store_sample('submit') is True

        key = KeyFactory(store_sample_locate=50)
        results = []
        for i in range(20):
            results.append(key.store_sample('locate'))
        assert True in results
        assert False in results
Пример #5
0
    def test_store_sample(self):
        key = KeyFactory(store_sample_locate=None, store_sample_submit=None)
        assert key.store_sample("locate") is False
        assert key.store_sample("submit") is False
        assert key.store_sample("region") is False

        key = KeyFactory(store_sample_locate=0, store_sample_submit=100)
        assert key.store_sample("locate") is False
        assert key.store_sample("submit") is True

        # A global_locate_sample_rate can turn off samples
        assert key.store_sample("locate", global_locate_sample_rate=0.0) is False

        # And can raise a sample rate
        key = KeyFactory(store_sample_locate=50, store_sample_submit=None)
        assert key.store_sample("locate", global_locate_sample_rate=200.0) is True