github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py (about)

     1  #
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  """Test for the BigQuery tornadoes example."""
    19  
    20  # pytype: skip-file
    21  
    22  import logging
    23  import unittest
    24  
    25  import apache_beam as beam
    26  from apache_beam.examples.cookbook import bigquery_tornadoes
    27  from apache_beam.testing.test_pipeline import TestPipeline
    28  from apache_beam.testing.util import assert_that
    29  from apache_beam.testing.util import equal_to
    30  
    31  
    32  class BigQueryTornadoesTest(unittest.TestCase):
    33    def test_basics(self):
    34      with TestPipeline() as p:
    35        rows = (
    36            p | 'create' >> beam.Create([{
    37                'month': 1, 'day': 1, 'tornado': False
    38            }, {
    39                'month': 1, 'day': 2, 'tornado': True
    40            }, {
    41                'month': 1, 'day': 3, 'tornado': True
    42            }, {
    43                'month': 2, 'day': 1, 'tornado': True
    44            }]))
    45        results = bigquery_tornadoes.count_tornadoes(rows)
    46        assert_that(
    47            results,
    48            equal_to([{
    49                'month': 1, 'tornado_count': 2
    50            }, {
    51                'month': 2, 'tornado_count': 1
    52            }]))
    53  
    54  
    55  if __name__ == '__main__':
    56    logging.getLogger().setLevel(logging.INFO)
    57    unittest.main()