Esempio n. 1
0
 def testIntegerScanning(self):
     self.assertEquals((42, 43), sscanf("   42\n   43  ", "%d %d"))
     self.assertEquals((8, ), sscanf("10", "%o"))
     self.assertEquals((8, ), sscanf("010", "%o"))
     self.assertEquals((15, ), sscanf("F", "%x"))
     self.assertEquals((15, ), sscanf("f", "%x"))
     self.assertEquals((15, ), sscanf("0xF", "%x"))
     self.assertEquals((15, ), sscanf("0XF", "%x"))
     self.assertEquals((15, ), sscanf("0Xf", "%x"))
     self.assertEquals((-1, -2, 3, -4), sscanf("-1-2+3-4", "%d%d%d%d"))
Esempio n. 2
0
 def testIntegerScanning(self):
     self.assertEquals((42, 43),
                       sscanf("   42\n   43  ", "%d %d"))
     self.assertEquals((8,), sscanf("10", "%o"))
     self.assertEquals((8,), sscanf("010", "%o"))
     self.assertEquals((15,), sscanf("F", "%x"))
     self.assertEquals((15,), sscanf("f", "%x"))
     self.assertEquals((15,), sscanf("0xF", "%x"))
     self.assertEquals((15,), sscanf("0XF", "%x"))
     self.assertEquals((15,), sscanf("0Xf", "%x"))
     self.assertEquals((-1, -2, 3, -4), sscanf("-1-2+3-4", "%d%d%d%d"))
Esempio n. 3
0
 def testFloats(self):
     self.assertEquals((3.14,
                        10.,
                        .001,
                        1e100,
                        3.14e-10,
                        0e0,), sscanf("""3.14
                        10.
                        .001
                        1e100
                        3.14e-10
                        0e0""", "%f %f %f %f %f %f"))
Esempio n. 4
0
    def testMoreSimpleScanningExamples(self):
        self.assertEquals((192, 168, 1, 1), sscanf("192.168.1.1",
                                                   "%d.%d.%d.%d"))
        self.assertEquals(("a", "b", "c"), sscanf("  ab   c  ", "%1s%1s%s"))
        self.assertEquals(("hello", " ", "world"),
                          sscanf("hello world", "%s%c%s"))
        self.assertRaises(IncompleteCaptureError, sscanf, "192.168.1.1",
                          "%d %d %d %d")
        self.assertEquals(("danny", ), sscanf("hi danny", "hi %s"))
        self.assertEquals(("danny", ), sscanf("  hi danny", "  hi %s"))
        self.assertEquals(("a", "b", 3), sscanf("ab3", "%c%c%d"))
        # this case is weird, but it happens in C too!
        self.assertRaises(IncompleteCaptureError, sscanf, "  hi danny",
                          "hi %s")

        # The example that's used in
        # 'http://docs.python.org/lib/node109.html'
        self.assertEquals(("/usr/bin/sendmail", 0, 4),
                          sscanf("/usr/bin/sendmail - 0 errors, 4 warnings",
                                 "%s - %d errors, %d warnings"))
Esempio n. 5
0
    def testMoreSimpleScanningExamples(self):
        self.assertEquals((192, 168, 1, 1),
                          sscanf("192.168.1.1", "%d.%d.%d.%d"))
        self.assertEquals(("a", "b", "c"),
                          sscanf("  ab   c  ", "%1s%1s%s"))
        self.assertEquals(("hello", " ", "world"),
                          sscanf("hello world", "%s%c%s"))
        self.assertRaises(IncompleteCaptureError,
                          sscanf, "192.168.1.1", "%d %d %d %d")
        self.assertEquals(("danny",),
                          sscanf("hi danny", "hi %s"))
        self.assertEquals(("danny",),
                          sscanf("  hi danny", "  hi %s"))
        self.assertEquals(("a", "b", 3),
                          sscanf("ab3", "%c%c%d"))
        # this case is weird, but it happens in C too!
        self.assertRaises(IncompleteCaptureError,
                          sscanf, "  hi danny", "hi %s")

        # The example that's used in
        # 'http://docs.python.org/lib/node109.html'
        self.assertEquals(("/usr/bin/sendmail", 0, 4),
                          sscanf("/usr/bin/sendmail - 0 errors, 4 warnings",
                                 "%s - %d errors, %d warnings"))
Esempio n. 6
0
 def testSkipLeadingSpaceOnScanning(self):
     """Ralph Heinkel reported a bug where floats weren't being
     parsed properly if there were leading whitespace for %f.
     This case checks that"""
     self.assertEquals((42.0, ), sscanf("    42.0", "%f"))
Esempio n. 7
0
 def testWidth(self):
     self.assertEquals(("00010", ), sscanf("00010101010111", "%5c"))
     self.assertEquals(("xy", ), sscanf("xyz", "%2s"))
     self.assertEquals(("xy", ), sscanf("              xyz", "%2s"))
     self.assertEquals(("  ", ), sscanf("              xyz", "%2c"))
Esempio n. 8
0
 def testSuppression(self):
     self.assertEquals((), sscanf(" hello world", "%*s %*s"))
     self.assertEquals(("happy", ), sscanf("hello happy world",
                                           "%*s %s %*s"))
     self.assertEquals((), sscanf("h", "%*c"))
Esempio n. 9
0
 def testWordScanning(self):
     self.assertEquals(("hello", "world"), sscanf("   hello world",
                                                  "%s %s"))
Esempio n. 10
0
 def testSkipLeadingSpaceOnScanning(self):
     """Ralph Heinkel reported a bug where floats weren't being
     parsed properly if there were leading whitespace for %f.
     This case checks that"""
     self.assertEquals((42.0,),
                       sscanf("    42.0", "%f"))
Esempio n. 11
0
 def testWidth(self):
     self.assertEquals(("00010",), sscanf("00010101010111", "%5c"))
     self.assertEquals(("xy",), sscanf("xyz", "%2s"))
     self.assertEquals(("xy",), sscanf("              xyz", "%2s"))
     self.assertEquals(("  ",), sscanf("              xyz", "%2c"))
Esempio n. 12
0
 def testSuppression(self):
     self.assertEquals((), sscanf(" hello world", "%*s %*s"))
     self.assertEquals(("happy",),
                       sscanf("hello happy world", "%*s %s %*s"))
     self.assertEquals((), sscanf("h", "%*c"))
Esempio n. 13
0
 def testWordScanning(self):
     self.assertEquals(("hello", "world"),
                       sscanf("   hello world", "%s %s"))