| 267 | #################### |
| 268 | |
| 269 | class FunctionGeneratorTestCase(unittest.TestCase): |
| 270 | def test_parseTypesInFmtString_noReplacements(self): |
| 271 | fmtString = """~S!@#$^&*()_+1234567890qwertyu |
| 272 | iopasdfghjkl;zxcv bnm,\\\\r\\n |
| 273 | %%ud \%lf osdif<>":L:]; |
| 274 | """ |
| 275 | |
| 276 | # No replacements should be performed because all % are escaped |
| 277 | self.assertEqual(splitAndParseTypesInFmtString(fmtString), |
| 278 | [(None, None, None, fmtString)]) |
| 279 | |
| 280 | fmtString = "" |
| 281 | self.assertEqual(splitAndParseTypesInFmtString(fmtString), |
| 282 | [(None, None, None, fmtString)]) |
| 283 | |
| 284 | fmtString = "Hello" |
| 285 | self.assertEqual(splitAndParseTypesInFmtString(fmtString), |
| 286 | [(None, None, None, fmtString)]) |
| 287 | |
| 288 | fmtString = "\% %%ud" |
| 289 | self.assertEqual(splitAndParseTypesInFmtString(fmtString), |
| 290 | [(None, None, None, fmtString)]) |
| 291 | |
| 292 | # Invalid types |
| 293 | fmtString = "%S %qosiwieud" |
| 294 | with self.assertRaisesRegexp(ValueError, |
| 295 | "Unrecognized Format Specifier"): |
| 296 | splitAndParseTypesInFmtString(fmtString) |
| 297 | |
| 298 | def test_parseTypesInFmtString_escapes(self): |
| 299 | # Tricky |
| 300 | fmtString = "\\%s %%p %%%s \\\\%s" |
| 301 | self.assertEqual(splitAndParseTypesInFmtString(fmtString), |
| 302 | [FmtType("const char*", None, None, '\\%s %%p %%%s'), |
| 303 | FmtType("const char*", None, None, ' \\\\%s')]) |
| 304 | |
| 305 | def test_parseTypesInFmtString_endingStrings(self): |
| 306 | self.assertEqual(splitAndParseTypesInFmtString("Hello"), |
| 307 | [FmtType(None, None, None, "Hello")]) |
| 308 | |
| 309 | self.assertEqual(splitAndParseTypesInFmtString("Hello %d"), |
| 310 | [FmtType('int', None, None, "Hello %d")]) |
| 311 | |
| 312 | self.assertEqual(splitAndParseTypesInFmtString("Hello %d Bye"), |
| 313 | [FmtType('int', None, None, "Hello %d Bye")]) |
| 314 | |
| 315 | self.assertEqual(splitAndParseTypesInFmtString("Hello %d Bye %s"), |
| 316 | [FmtType('int', None, None, "Hello %d"), |
| 317 | FmtType('const char*', None, None, " Bye %s")]) |
| 318 | |
| 319 | def test_parseTypesInFmtString_charTypes(self): |
| 320 | self.assertEqual(splitAndParseTypesInFmtString("%hhd %hhi"), |
| 321 | [FmtType("signed char", None, None, "%hhd"), |
| 322 | FmtType("signed char", None, None, " %hhi")]) |
| 323 | self.assertEqual(splitAndParseTypesInFmtString(" %d"), |
| 324 | [FmtType("int", None, None, " %d")]) |
| 325 | |
| 326 | with self.assertRaisesRegexp(ValueError, "not supported"): |
nothing calls this directly
no outgoing calls
no test coverage detected