Пример #1
0
def check_saturated_total(actual):
  expected = '''[START saturated_total]
('🥕', 5)
('🍆', 1)
('🍅', 8)
[END saturated_total]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #2
0
def check_bounded_total(actual):
  expected = '''[START bounded_total]
('🥕', 5)
('🍆', 2)
('🍅', 8)
[END bounded_total]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #3
0
def check_largest_elements_per_key(actual):
    expected = '''[START largest_elements_per_key]
('🥕', [3, 2])
('🍆', [1])
('🍅', [5, 4])
[END largest_elements_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #4
0
def check_unique_elements(actual):
  expected = '''[START unique_elements]
🥕
🍆
🍅
[END unique_elements]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #5
0
def check_smallest_elements_per_key(actual):
    expected = '''[START smallest_elements_per_key]
('🥕', [2, 3])
('🍆', [1])
('🍅', [3, 4])
[END smallest_elements_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #6
0
def check_perennials(actual):
    expected = '''[START perennials]
{'icon': '🍓', 'name': 'Strawberry', 'duration': 'perennial'}
{'icon': '🍆', 'name': 'Eggplant', 'duration': 'perennial'}
{'icon': '🥔', 'name': 'Potato', 'duration': 'perennial'}
[END perennials]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #7
0
 def test_assert_matches_stdout_object(self):
     expected = [
         "{'a': '🍓', 'b': True}",
         "{'a': '🥕', 'b': 42}",
         "{'a': '🍆', 'b': '\"hello\"'}",
         "{'a': '🍅', 'b': [1, 2, 3]}",
         "{'b': 'B', 'a': '🥔'}",
     ]
     with TestPipeline() as pipeline:
         actual = (pipeline
                   | beam.Create([
                       {
                           'a': '🍓',
                           'b': True
                       },
                       {
                           'a': '🥕',
                           'b': 42
                       },
                       {
                           'a': '🍆',
                           'b': '"hello"'
                       },
                       {
                           'a': '🍅',
                           'b': [1, 2, 3]
                       },
                       {
                           'a': '🥔',
                           'b': 'B'
                       },
                   ])
                   | beam.Map(str))
         util.assert_matches_stdout(actual, expected)
Пример #8
0
 def test_assert_matches_stdout_string(self):
     expected = ['🍓', '🥕', '🍆', '🍅', '🥔']
     with TestPipeline() as pipeline:
         actual = (pipeline
                   | beam.Create(['🍓', '🥕', '🍆', '🍅', '🥔'])
                   | beam.Map(str))
         util.assert_matches_stdout(actual, expected)
Пример #9
0
def check_elements_with_min_value_per_key(actual):
    expected = '''[START elements_with_min_value_per_key]
('🥕', 2)
('🍆', 1)
('🍅', 3)
[END elements_with_min_value_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #10
0
def check_average(actual):
  expected = '''[START average]
('🥕', 2.5)
('🍆', 1.0)
('🍅', 4.0)
[END average]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #11
0
def check_totals_per_key(actual):
  expected = '''[START totals_per_key]
('🥕', 5)
('🍆', 1)
('🍅', 12)
[END totals_per_key]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #12
0
def check_percentages_per_season(actual):
  expected = '''[START percentages_per_season]
('spring', {'🥕': 0.4, '🍅': 0.4, '🍆': 0.2})
('summer', {'🥕': 0.2, '🍅': 0.6, '🌽': 0.2})
('fall', {'🥕': 0.5, '🍅': 0.5})
('winter', {'🍆': 1.0})
[END percentages_per_season]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #13
0
def check_valid_plants(actual):
    expected = '''[START valid_plants]
{'icon': '🍓', 'name': 'Strawberry', 'duration': 'perennial'}
{'icon': '🥕', 'name': 'Carrot', 'duration': 'biennial'}
{'icon': '🍆', 'name': 'Eggplant', 'duration': 'perennial'}
{'icon': '🍅', 'name': 'Tomato', 'duration': 'annual'}
[END valid_plants]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #14
0
def check_latest_elements_per_key(actual):
    expected = '''[START latest_elements_per_key]
('spring', '🥕')
('summer', '🍅')
('autumn', '🍆')
('winter', '🥬')
[END latest_elements_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #15
0
def check_total_elements_per_key(actual):
    expected = '''[START total_elements_per_key]
('spring', 4)
('summer', 3)
('fall', 2)
('winter', 1)
[END total_elements_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #16
0
def check_shortest_elements_per_key(actual):
    expected = '''[START shortest_elements_per_key]
('spring', ['🥕 Carrot', '🍓 Strawberry'])
('summer', ['🌽 Corn', '🥕 Carrot'])
('fall', ['🥕 Carrot', '🍏 Green apple'])
('winter', ['🍆 Eggplant'])
[END shortest_elements_per_key]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #17
0
def check_all_matches(actual):
    expected = '''[START plants_all_matches]
['🍓, Strawberry, perennial', '🍓', 'Strawberry', 'perennial']
['🥕, Carrot, biennial', '🥕', 'Carrot', 'biennial']
['🍆, Eggplant, perennial', '🍆', 'Eggplant', 'perennial']
['🍅, Tomato, annual', '🍅', 'Tomato', 'annual']
['🥔, Potato, perennial', '🥔', 'Potato', 'perennial']
[END plants_all_matches]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #18
0
def check_plants_csv(actual):
    expected = '''[START plants_csv]
🍓,Strawberry,perennial
🥕,Carrot,biennial
🍆,Eggplant,perennial
🍅,Tomato,annual
🥔,Potato,perennial
[END plants_csv]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #19
0
def check_plant_lists(actual):
    expected = '''[START plant_lists]
['🍓', 'Strawberry', 'perennial']
['🥕', 'Carrot', 'biennial']
['🍆', 'Eggplant', 'perennial']
['🍅', 'Tomato', 'annual']
['🥔', 'Potato', 'perennial']
[END plant_lists]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #20
0
def check_plants(actual):
    expected = '''[START plants]
🍓,Strawberry
🥕,Carrot
🍆,Eggplant
🍅,Tomato
🥔,Potato
[END plants]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #21
0
def check_plant_timestamps(actual):
    expected = '''[START plant_timestamps]
2020-04-01 00:00:00 - Strawberry
2020-06-01 00:00:00 - Carrot
2020-03-01 00:00:00 - Artichoke
2020-05-01 00:00:00 - Tomato
2020-09-01 00:00:00 - Potato
[END plant_timestamps]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #22
0
def check_total_unique_elements(actual):
    expected = '''[START total_unique_elements]
('🍓', 1)
('🥕', 3)
('🍆', 2)
('🍅', 3)
('🌽', 1)
[END total_unique_elements]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #23
0
def check_plant_events(actual):
    expected = '''[START plant_events]
1 - Strawberry
4 - Carrot
2 - Artichoke
3 - Tomato
5 - Potato
[END plant_events]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #24
0
def check_samples_per_key(actual):
  expected = '''[START samples_per_key]
('spring', ['🍓', '🥕', '🍆'])
('summer', ['🥕', '🍅', '🌽'])
('fall', ['🥕', '🍅'])
('winter', ['🍆'])
[END samples_per_key]'''.splitlines()[1:-1]
  # The sampled elements are non-deterministic, so check the sample size.
  assert_matches_stdout(actual, expected, lambda pair: (pair[0], len(pair[1])))
Пример #25
0
def check_plants(actual):
    expected = '''[START plants]
Strawberry
Carrot
Eggplant
Tomato
Potato
[END plants]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #26
0
def check_icons(actual):
  expected = '''[START icons]
🍓
🥕
🍆
🍅
🥔
[END icons]'''.splitlines()[1:-1]
  assert_matches_stdout(actual, expected)
Пример #27
0
def check_find_all(actual):
    expected = '''[START plants_find_all]
['🍓, Strawberry, perennial']
['🥕, Carrot, biennial']
['🍆, Eggplant, perennial', '🍌, Banana, perennial']
['🍅, Tomato, annual', '🍉, Watermelon, annual']
['🥔, Potato, perennial']
[END plants_find_all]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #28
0
def check_matches_kv(actual):
    expected = '''[START plants_matches_kv]
('🍓', '🍓, Strawberry, perennial')
('🥕', '🥕, Carrot, biennial')
('🍆', '🍆, Eggplant, perennial')
('🍅', '🍅, Tomato, annual')
('🥔', '🥔, Potato, perennial')
[END plants_matches_kv]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #29
0
def check_plants(actual):
    expected = '''[START plants]
('Strawberry', '🍓')
('Carrot', '🥕')
('Eggplant', '🍆')
('Tomato', '🍅')
('Potato', '🥔')
[END plants]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)
Пример #30
0
def check_replace_first(actual):
    expected = '''[START plants_replace_first]
🍓: Strawberry, perennial
🥕: Carrot, biennial
🍆: Eggplant, perennial
🍅: Tomato, annual
🥔: Potato, perennial
[END plants_replace_first]'''.splitlines()[1:-1]
    assert_matches_stdout(actual, expected)