github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/testing/extra_assertions_test.py (about) 1 # -*- coding: utf-8 -*- 2 # 3 # Licensed to the Apache Software Foundation (ASF) under one or more 4 # contributor license agreements. See the NOTICE file distributed with 5 # this work for additional information regarding copyright ownership. 6 # The ASF licenses this file to You under the Apache License, Version 2.0 7 # (the "License"); you may not use this file except in compliance with 8 # the License. You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 # pytype: skip-file 19 20 import logging 21 import unittest 22 23 import numpy as np 24 25 from apache_beam.testing.extra_assertions import ExtraAssertionsMixin 26 27 28 class ExtraAssertionsMixinTest(ExtraAssertionsMixin, unittest.TestCase): 29 def test_assert_array_count_equal_strings(self): 30 data1 = [u"±♠Ωℑ", u"hello", "world"] 31 data2 = ["hello", u"±♠Ωℑ", u"world"] 32 self.assertUnhashableCountEqual(data1, data2) 33 34 def test_assert_array_count_equal_mixed(self): 35 data1 = [ 36 { 37 'a': 1, 123: 1.234 38 }, 39 ['d', 1], 40 u"±♠Ωℑ", 41 np.zeros((3, 6)), 42 (1, 2, 3, 'b'), 43 'def', 44 100, 45 'abc', 46 ('a', 'b', 'c'), 47 None, 48 ] 49 data2 = [ 50 { 51 123: 1.234, 'a': 1 52 }, 53 ('a', 'b', 'c'), 54 ['d', 1], 55 None, 56 'abc', 57 'def', 58 u"±♠Ωℑ", 59 100, 60 (1, 2, 3, 'b'), 61 np.zeros((3, 6)), 62 ] 63 self.assertUnhashableCountEqual(data1, data2) 64 self.assertUnhashableCountEqual(data1 * 2, data2 * 2) 65 66 def test_assert_not_equal(self): 67 data1 = [{'a': 123, 'b': 321}, [1, 2, 3]] 68 data2 = [{'a': 123, 'c': 321}, [1, 2, 3]] 69 with self.assertRaises(AssertionError): 70 self.assertUnhashableCountEqual(data1, data2) 71 72 73 if __name__ == '__main__': 74 logging.getLogger().setLevel(logging.INFO) 75 unittest.main()