github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/tools/microbenchmarks_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 """Unit tests for microbenchmarks code.""" 19 20 # pytype: skip-file 21 22 import unittest 23 24 from pkg_resources import DistributionNotFound 25 from pkg_resources import get_distribution 26 27 from apache_beam.tools import coders_microbenchmark 28 from apache_beam.tools import utils 29 30 31 class MicrobenchmarksTest(unittest.TestCase): 32 def test_coders_microbenchmark(self): 33 # Right now, we don't evaluate performance impact, only check that 34 # microbenchmark code can successfully run. 35 coders_microbenchmark.run_coder_benchmarks( 36 num_runs=1, input_size=10, seed=1, verbose=False) 37 38 def is_cython_installed(self): 39 try: 40 get_distribution('cython') 41 return True 42 except DistributionNotFound: 43 return False 44 45 def test_check_compiled(self): 46 if self.is_cython_installed(): 47 utils.check_compiled('apache_beam.runners.worker.opcounters') 48 # Unfortunately, if cython is not installed, that doesn't mean we 49 # can rule out compiled modules (e.g. if Beam was installed from a wheel). 50 # Technically the other way around could be true as well, e.g. if 51 # Cython was installed after Beam, but this is rarer and more easily 52 # remedied. 53 54 55 if __name__ == '__main__': 56 unittest.main()