(value)
| 158 | |
| 159 | |
| 160 | def convert_value(value): |
| 161 | # Convert timestamps to strings for comparison, format: '2021-09-01T12:34:56.123456Z' |
| 162 | if isinstance(value, datetime.datetime): |
| 163 | return value.strftime('%Y-%m-%dT%H:%M:%S.%fZ') |
| 164 | |
| 165 | # Convert bytes to char |
| 166 | elif isinstance(value, bytes): |
| 167 | return value.decode() |
| 168 | |
| 169 | # Recursively handle lists |
| 170 | elif isinstance(value, list): |
| 171 | # Handle nested lists |
| 172 | if value and isinstance(value[0], list): |
| 173 | nested_items = [convert_value(item) for item in value] |
| 174 | # If nested_items are already in PostgreSQL array format (start with '{') |
| 175 | if all(isinstance(item, str) and item.startswith('{') for item in nested_items): |
| 176 | return '{' + ','.join(nested_items) + '}' |
| 177 | else: |
| 178 | # Otherwise, wrap each nested list in braces |
| 179 | return '{' + ''.join('{' + str(item)[1:-1] + '}' for item in nested_items) + '}' |
| 180 | |
| 181 | # Process flat lists of numbers or None values for PostgreSQL array formatting |
| 182 | elif all(isinstance(item, (int, float, type(None))) for item in value): |
| 183 | float_strs = [] |
| 184 | for item in value: |
| 185 | if item is None: |
| 186 | float_strs.append("NULL") |
| 187 | else: |
| 188 | float_val = float(item) |
| 189 | # Check if it's an integer value and add .0 if needed |
| 190 | if float_val.is_integer(): |
| 191 | float_strs.append(f"{float_val:.1f}") |
| 192 | else: |
| 193 | float_strs.append(str(float_val)) |
| 194 | return '{' + ','.join(float_strs) + '}' |
| 195 | |
| 196 | # For other types of lists, recursively convert each item |
| 197 | else: |
| 198 | return [convert_value(item) for item in value] |
| 199 | |
| 200 | # Handle dictionaries by recursively converting their values |
| 201 | elif isinstance(value, dict): |
| 202 | return {k: convert_value(v) for k, v in value.items()} |
| 203 | |
| 204 | # Handle decimal to print them as string |
| 205 | elif isinstance(value, Decimal): |
| 206 | return value.normalize().__str__() |
| 207 | |
| 208 | # Return other types unchanged |
| 209 | else: |
| 210 | return value |
| 211 | |
| 212 | |
| 213 | def assert_result(expect, actual): |
no test coverage detected
searching dependent graphs…