本文整理汇总了Python中tests.support.test_helpers.d函数的典型用法代码示例。如果您正苦于以下问题:Python d函数的具体用法?Python d怎么用?Python d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了d函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_period_group_query_adds_missing_periods_in_correct_order
def test_period_group_query_adds_missing_periods_in_correct_order(self):
self.mock_storage.execute_query.return_value = [
{'some_group': 'val1', '_week_start_at': d(2013, 1, 14), '_count': 23},
{'some_group': 'val1', '_week_start_at': d(2013, 1, 21), '_count': 41},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 14), '_count': 31},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 28), '_count': 12},
]
data = self.data_set.execute_query(
Query.create(period=WEEK, group_by=['some_group'],
start_at=d_tz(2013, 1, 7, 0, 0, 0),
end_at=d_tz(2013, 2, 4, 0, 0, 0)))
assert_that(data, has_item(has_entries({
"some_group": "val1",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
),
})))
assert_that(data, has_item(has_entries({
"some_group": "val2",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
),
})))
示例2: test_query_with_start_at_and__end_at
def test_query_with_start_at_and__end_at(self):
query = Query.create(end_at=d(2013, 3, 1, 12, 0, 0),
start_at=d(2013, 2, 1, 12, 0, 0))
self.bucket.query(query)
self.mock_repository.find.assert_called_with(query, sort=None,
limit=None)
示例3: test_sorted_week_and_group_query_with_limit
def test_sorted_week_and_group_query_with_limit(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 7, 0, 0, 0),
"_count": 1
},
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 5
}
]
}
]
query = Query.create(period="week", group_by="some_group",
sort_by=["_count", "descending"], limit=1,
collect=[])
self.bucket.query(query)
self.mock_repository.multi_group.assert_called_with(
"some_group",
"_week_start_at",
query,
sort=["_count", "descending"],
limit=1,
collect=[])
示例4: test_period_group_query_fails_when_weeks_do_not_start_on_monday
def test_period_group_query_fails_when_weeks_do_not_start_on_monday(self):
multi_group_results = [
{
"is": "Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 1), "_count": 1}
]
},
{
"is": "also Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 8), "_count": 1}
]
},
{
"is": "Tuesday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 9), "_count": 1}
]
},
]
self.mock_repository.multi_group.return_value = \
multi_group_results
query = Query.create(period=WEEK, group_by='d')
assert_raises(ValueError, self.bucket.query, query)
示例5: test_period_group_query_fails_when_weeks_do_not_start_on_monday
def test_period_group_query_fails_when_weeks_do_not_start_on_monday(self):
multi_group_results = [
{
"is": "Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 1), "_count": 1}
]
},
{
"is": "also Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 8), "_count": 1}
]
},
{
"is": "Tuesday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 9), "_count": 1}
]
},
]
self.mock_repository.multi_group.return_value = \
multi_group_results
try:
self.bucket.query(Query.create(period='week', group_by='d')).data()
assert_that(False)
except ValueError as e:
assert_that(str(e), is_(
"Weeks MUST start on Monday but got date: 2013-04-09 00:00:00"
))
示例6: test_period_group_query_adds_missing_periods_in_correct_order
def test_period_group_query_adds_missing_periods_in_correct_order(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 23
},
{
"_week_start_at": d(2013, 1, 21, 0, 0, 0),
"_count": 41
}
]
},
{
"some_group": "val2",
"_count": 8,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 31
},
{
"_week_start_at": d(2013, 1, 28, 0, 0, 0),
"_count": 12
}
]
}
]
query_result = self.bucket.query(
Query.create(period="week", group_by="some_group",
start_at=d_tz(2013, 1, 7, 0, 0, 0),
end_at=d_tz(2013, 2, 4, 0, 0, 0))).data()
assert_that(query_result, has_item(has_entries({
"some_group": "val1",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
),
})))
assert_that(query_result, has_item(has_entries({
"some_group": "val2",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
),
})))
示例7: test_that_it_returns_the_end_of_the_current_month
def test_that_it_returns_the_end_of_the_current_month(self):
some_datetime = d(2013, 10, 4, 10, 23, 43)
some_other_datetime = d(2013, 10, 4)
end = MONTH.end(some_datetime)
other_end = MONTH.end(some_other_datetime)
assert_that(end, is_(d(2013, 11, 1)))
assert_that(other_end, is_(d(2013, 11, 1)))
示例8: test_adding_multiple_mongo_documents
def test_adding_multiple_mongo_documents(self):
stub_document_1 = {
"_subgroup": [ {"_week_start_at": d(2013, 4, 1), "_count": 5} ]
}
stub_document_2 = {
"_subgroup": [ {"_week_start_at": d(2013, 4, 1), "_count": 5} ]
}
data = PeriodGroupedData([stub_document_1, stub_document_2], WEEK)
assert_that(data.data(), has_length(2))
示例9: test_that_middle_of_quarters_are_invalid
def test_that_middle_of_quarters_are_invalid(self):
middle_first_quarter = d(2013, 1, 10, 0, 0, 0)
middle_second_quarter = d(2013, 4, 15, 0, 0, 0)
middle_third_quarter = d(2013, 7, 20, 0, 0, 0)
middle_fourth_quarter = d(2013, 10, 13, 0, 0, 0)
assert_that(QUARTER.valid_start_at(middle_first_quarter), is_(False))
assert_that(QUARTER.valid_start_at(middle_second_quarter), is_(False))
assert_that(QUARTER.valid_start_at(middle_third_quarter), is_(False))
assert_that(QUARTER.valid_start_at(middle_fourth_quarter), is_(False))
示例10: test_that_beginning_of_quarters_are_valid
def test_that_beginning_of_quarters_are_valid(self):
first_quarter = d(2013, 1, 1, 0, 0, 0)
second_quarter = d(2013, 4, 1, 0, 0, 0)
third_quarter = d(2013, 7, 1, 0, 0, 0)
fourth_quarter = d(2013, 10, 1, 0, 0, 0)
assert_that(QUARTER.valid_start_at(first_quarter), is_(True))
assert_that(QUARTER.valid_start_at(second_quarter), is_(True))
assert_that(QUARTER.valid_start_at(third_quarter), is_(True))
assert_that(QUARTER.valid_start_at(fourth_quarter), is_(True))
示例11: test_period_query_fails_when_months_do_not_start_on_the_1st
def test_period_query_fails_when_months_do_not_start_on_the_1st(self):
self.mock_storage.execute_query.return_value = [
{"_month_start_at": d(2013, 1, 7, 0, 0, 0), "_count": 3},
{"_month_start_at": d(2013, 2, 8, 0, 0, 0), "_count": 1},
]
assert_raises(
ValueError,
self.data_set.execute_query,
Query.create(period=MONTH)
)
示例12: test_period_query_fails_when_months_do_not_start_on_the_1st
def test_period_query_fails_when_months_do_not_start_on_the_1st(self):
self.mock_repository.group.return_value = [
{"_month_start_at": d(2013, 1, 7, 0, 0, 0), "_count": 3},
{"_month_start_at": d(2013, 2, 8, 0, 0, 0), "_count": 1},
]
self.assertRaises(
ValueError,
self.bucket.query,
Query.create(period='month')
)
示例13: test_month_query
def test_month_query(self):
self.mock_repository.group.return_value = [
{"_month_start_at": d(2013, 4, 1), "_count": 1},
{"_month_start_at": d(2013, 5, 1), "_count": 3}
]
query = Query.create(period="month")
query_result = self.bucket.query(query).data()
self.mock_repository.group.assert_called_once_with(
"_month_start_at", query, sort=['_month_start_at', 'ascending'],
limit=None, collect=[])
示例14: test_period_query_fails_when_weeks_do_not_start_on_monday
def test_period_query_fails_when_weeks_do_not_start_on_monday(self):
self.mock_storage.execute_query.return_value = [
{"_week_start_at": d(2013, 1, 7, 0, 0, 0), "_count": 3},
{"_week_start_at": d(2013, 1, 8, 0, 0, 0), "_count": 1},
]
assert_raises(
ValueError,
self.data_set.execute_query,
Query.create(period=WEEK)
)
示例15: test_key1_is_pulled_to_the_top_of_outer_group
def test_key1_is_pulled_to_the_top_of_outer_group(self):
self.setUpPeopleLocationData()
results = self.repo.multi_group("_week_start_at", "person", Query.create())
assert_that(results, has_item(has_entry(
"_week_start_at", d(2013, 3, 11)
)))
assert_that(results, has_item(has_entry(
"_week_start_at", d(2013, 3, 25)
)))