|
| 1 | +import inspect |
| 2 | +import pptx |
| 3 | +import unittest |
| 4 | +from typing import Iterable, overload |
| 5 | +from opencsp.common.lib.render.lib.PowerpointShape import PowerpointShape |
| 6 | + |
| 7 | + |
| 8 | +class test_PowerpointShape(unittest.TestCase): |
| 9 | + # Test of a single integer value |
| 10 | + def test_pptx_inches_single_integer(self): |
| 11 | + ppt_shape_instance = PowerpointShape() |
| 12 | + result = ppt_shape_instance._pptx_inches(vals=3) |
| 13 | + assert result == pptx.util.Inches(3) |
| 14 | + |
| 15 | + # Test of a single float value |
| 16 | + def test_pptx_inches_single_float(self): |
| 17 | + ppt_shape_instance = PowerpointShape() |
| 18 | + result = ppt_shape_instance._pptx_inches(vals=6.0) |
| 19 | + assert result == pptx.util.Inches(6.0) |
| 20 | + |
| 21 | + # Test for a None value |
| 22 | + def test_pptx_inches_none(self): |
| 23 | + ppt_shape_instance = PowerpointShape() |
| 24 | + with self.assertRaises(TypeError): |
| 25 | + ppt_shape_instance._pptx_inches(None) |
| 26 | + |
| 27 | + # Test for a list of integer values |
| 28 | + def test_pptx_inches_list_of_integers(self): |
| 29 | + ppt_shape_instance = PowerpointShape() |
| 30 | + result = ppt_shape_instance._pptx_inches(vals=[1, 2, 3, 4, 5]) |
| 31 | + expected = [ |
| 32 | + pptx.util.Inches(1), |
| 33 | + pptx.util.Inches(2), |
| 34 | + pptx.util.Inches(3), |
| 35 | + pptx.util.Inches(4), |
| 36 | + pptx.util.Inches(5), |
| 37 | + ] |
| 38 | + assert expected == result |
| 39 | + |
| 40 | + # Test for a list of float values |
| 41 | + def test_pptx_inches_list_of_floats(self): |
| 42 | + ppt_shape_instance = PowerpointShape() |
| 43 | + result = ppt_shape_instance._pptx_inches(vals=[1.0, 1.1, 1.2, 1.3, 1.4]) |
| 44 | + expected = [ |
| 45 | + pptx.util.Inches(1.0), |
| 46 | + pptx.util.Inches(1.1), |
| 47 | + pptx.util.Inches(1.2), |
| 48 | + pptx.util.Inches(1.3), |
| 49 | + pptx.util.Inches(1.4), |
| 50 | + ] |
| 51 | + assert expected == result |
| 52 | + |
| 53 | + # Test for a tuple of integers |
| 54 | + def test_pptx_inches_tuple_of_integers(self): |
| 55 | + ppt_shape_instance = PowerpointShape() |
| 56 | + result = ppt_shape_instance._pptx_inches(vals=(1, 2, 3, 4, 5)) |
| 57 | + expected = [ |
| 58 | + pptx.util.Inches(1), |
| 59 | + pptx.util.Inches(2), |
| 60 | + pptx.util.Inches(3), |
| 61 | + pptx.util.Inches(4), |
| 62 | + pptx.util.Inches(5), |
| 63 | + ] |
| 64 | + assert expected == result |
| 65 | + |
| 66 | + # Test for a tuple of floats |
| 67 | + def test_pptx_inches_tuple_of_floats(self): |
| 68 | + ppt_shape_instance = PowerpointShape() |
| 69 | + result = ppt_shape_instance._pptx_inches(vals=(1.0, 1.1, 1.2, 1.3, 1.4)) |
| 70 | + expected = [ |
| 71 | + pptx.util.Inches(1.0), |
| 72 | + pptx.util.Inches(1.1), |
| 73 | + pptx.util.Inches(1.2), |
| 74 | + pptx.util.Inches(1.3), |
| 75 | + pptx.util.Inches(1.4), |
| 76 | + ] |
| 77 | + assert expected == result |
| 78 | + |
| 79 | + # Test for a tuple of integers |
| 80 | + def test_pptx_inches_tuple_of_integers(self): |
| 81 | + ppt_shape_instance = PowerpointShape() |
| 82 | + with self.assertRaises(TypeError): |
| 83 | + ppt_shape_instance._pptx_inches(vals=(1, 2, "random string", 4, 5)) |
| 84 | + |
| 85 | + # Test for an empty list |
| 86 | + def test_pptx_inches_empty_list(self): |
| 87 | + ppt_shape_instance = PowerpointShape() |
| 88 | + result = ppt_shape_instance._pptx_inches(vals=[]) |
| 89 | + expected = [] |
| 90 | + assert expected == result |
| 91 | + |
| 92 | + # Test for a set, not supported |
| 93 | + def test_unsupported_type_set(self): |
| 94 | + ppt_shape_instance = PowerpointShape() |
| 95 | + with self.assertRaises(TypeError): |
| 96 | + ppt_shape_instance._pptx_inches({1, 2, 3}) |
| 97 | + |
| 98 | + # Test for a string, not supported |
| 99 | + def test_bad_string(self): |
| 100 | + ppt_shape_instance = PowerpointShape() |
| 101 | + with self.assertRaises(TypeError): |
| 102 | + ppt_shape_instance._pptx_inches("some string") |
| 103 | + |
| 104 | + # Test for a dictionary, not supported |
| 105 | + def test_unsupported_type_dictionary(self): |
| 106 | + ppt_shape_instance = PowerpointShape() |
| 107 | + with self.assertRaises(TypeError): |
| 108 | + ppt_shape_instance._pptx_inches({1: 3, 2: 4, 3: 5}) |
| 109 | + |
| 110 | + # Test for a list of strings, not supported |
| 111 | + def test_unsupported_type_list_of_strings(self): |
| 112 | + ppt_shape_instance = PowerpointShape() |
| 113 | + with self.assertRaises(TypeError): |
| 114 | + ppt_shape_instance._pptx_inches(["unit", "test", "for", "string", "list"]) |
| 115 | + |
| 116 | + # Test for a None value |
| 117 | + def test_dims_to_str_with_none(self): |
| 118 | + ppt_shape_instance = PowerpointShape() |
| 119 | + result = ppt_shape_instance._dims_to_str(dims=None) |
| 120 | + expected = None |
| 121 | + assert expected == result |
| 122 | + |
| 123 | + # Test converting tuple to string (csv) |
| 124 | + def test_dims_to_str_with_tuple(self): |
| 125 | + ppt_shape_instance = PowerpointShape() |
| 126 | + result = ppt_shape_instance._dims_to_str(dims=(5.1, 4.2, 3.3, 2.4, 1.5)) |
| 127 | + expected = "5.1,4.2,3.3,2.4,1.5" |
| 128 | + assert expected == result |
| 129 | + |
| 130 | + # Test converting a csv string to a tuple of floats |
| 131 | + def test_str_to_dims_with_tuple(self): |
| 132 | + ppt_shape_instance = PowerpointShape() |
| 133 | + result = ppt_shape_instance._str_to_dims(sval="1.1,2.2,3.3,4.4,5.5") |
| 134 | + expected = (1.1, 2.2, 3.3, 4.4, 5.5) |
| 135 | + assert expected == result |
| 136 | + |
| 137 | + # Test with sval equal to None |
| 138 | + def test_str_to_dims_with_none(self): |
| 139 | + ppt_shape_instance = PowerpointShape() |
| 140 | + result = ppt_shape_instance._str_to_dims(sval=None) |
| 141 | + expected = None |
| 142 | + assert expected == result |
0 commit comments