Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Standard Cyborg Utils test module 

3""" 

4 

5import unittest 

6from unittest import TestCase 

7 

8import pandas as pd 

9 

10from sdc_etl_libs.api_helpers.apis.StandardCyborg.StandardCyborgUtils import (Fields, add_columns_to_df, filter_data, get_image_file_extension, 

11 is_a_valid_asset) 

12 

13 

14# pylint: disable=R0201 

15class TestStandarCyborg(TestCase): 

16 """ 

17 Test suite for Standard Cyborg Utils 

18 """ 

19 

20 def test_add_columns_to_df(self): 

21 data = [['a', 10], ['b', 11], ['c', 12]] 

22 df = pd.DataFrame(data, columns=['A', 'B']) 

23 new_column_names = {"C": "c", "D": "d"} 

24 

25 result_df = add_columns_to_df(df, new_column_names) 

26 self.assertListEqual(list(result_df.columns), ["A", "B", "C", "D"]) 

27 

28 def test_filter_data(self): 

29 data = [[1, "a@test.com"], [2, "b@test.com"], [3, "c@test.com"], [4, None]] 

30 df = pd.DataFrame(data, columns=["ID", Fields.EMAIL]) 

31 serra_info = {"a@test.com": "a", "b@test.com": "b"} 

32 

33 result_df = filter_data(df, serra_info) 

34 self.assertListEqual(list(result_df["ID"]), [1, 2]) 

35 

36 def test_is_a_valid_asset(self): 

37 pass 

38 

39 def test_get_image_file_extension(self): 

40 path1 = "some/path/for/an/image.png" 

41 path2 = "some/path/for.an/image.jpg" 

42 path3 = "p/OTHER/2020-01-11 17:03:37.041147+00:00_OPEN_UP_OUT_REFINE_C000162b0e6e04" 

43 

44 self.assertEqual(get_image_file_extension(path1), ".png") 

45 self.assertEqual(get_image_file_extension(path2), ".jpg") 

46 self.assertEqual(get_image_file_extension(path3), "_OPEN_UP_OUT_REFINE.jpeg") 

47 

48 

49if __name__ == "__main__": 

50 unittest.main()