示例#1
0
 def test_bunch_not_all_tuples(self):
     header = ("A","B","C","D", "E")
     num_cols = len(header)
     NUM_ROWS = 10
     rows = [header]
     types = [int, str, unicode, float]
     tidx = 0
     for i in range(NUM_ROWS):
         row = []
         for n in range(1,num_cols+1):
             v = (i+1)*n
             t = types[tidx]
             tidx += 1
             if tidx>=len(types):
                 tidx = 0
             if t in (unicode, str):
                 v = t(v)*v
             else:
                 v = t(v)
             row.append(v)
         rows.append(row)
     sout = printrows.sprint_rows_as_text(rows)        
     out_rows = [r.split() for r in sout.strip().split("\n")]
     self.assertTrue(len(out_rows)==(NUM_ROWS+2), "Got %s rows, expected %s\n%s" % (len(out_rows), NUM_ROWS+2, sout))
     for idx, row in enumerate(out_rows):
         self.assertTrue(len(row)==num_cols, "Row #%s got %s cols, expected %s\n%s" % (idx, len(row), num_cols, sout))
示例#2
0
 def test_bunch_not_all_tuples(self):
     header = ("A", "B", "C", "D", "E")
     num_cols = len(header)
     NUM_ROWS = 10
     rows = [header]
     types = [int, str, unicode, float]
     tidx = 0
     for i in range(NUM_ROWS):
         row = []
         for n in range(1, num_cols + 1):
             v = (i + 1) * n
             t = types[tidx]
             tidx += 1
             if tidx >= len(types):
                 tidx = 0
             if t in (unicode, str):
                 v = t(v) * v
             else:
                 v = t(v)
             row.append(v)
         rows.append(row)
     sout = printrows.sprint_rows_as_text(rows)
     out_rows = [r.split() for r in sout.strip().split("\n")]
     self.assertTrue(
         len(out_rows) == (NUM_ROWS + 2), "Got %s rows, expected %s\n%s" %
         (len(out_rows), NUM_ROWS + 2, sout))
     for idx, row in enumerate(out_rows):
         self.assertTrue(
             len(row) == num_cols, "Row #%s got %s cols, expected %s\n%s" %
             (idx, len(row), num_cols, sout))
示例#3
0
 def test_one_not_header(self):
     sout = printrows.sprint_rows_as_text([("A", "B", "C")], first_is_header=False)        
     self.assertTrue(sout, sout)
     rows = sout.split("\n")
     self.assertTrue(len(rows)==2, "len: %s\n%s" % (len(rows), sout))
     self.failIf(rows[1].strip(), sout)
     self.assertTrue(rows[0].split()[0]=="A", sout)
     self.assertTrue(rows[0].split()[1]=="B", sout)
     self.assertTrue(rows[0].split()[2]=="C", sout)
示例#4
0
 def test_unicode(self):
     rows = [["A", "B", "C", "D", "E", "F"],
             [
                 'Account', 'Business_Classification_Cleansed__c',
                 u'Business Classification \u2013 Cleansed', 'string(13)',
                 '', ''
             ]]
     sout = printrows.sprint_rows_as_text(rows)
     self.assertEqual(len(sout.split("\n")), 4)
     self.assertIn(u'Business Classification \u2013 Cleansed', sout)
示例#5
0
 def test_one_not_header(self):
     sout = printrows.sprint_rows_as_text([("A", "B", "C")],
                                          first_is_header=False)
     self.assertTrue(sout, sout)
     rows = sout.split("\n")
     self.assertTrue(len(rows) == 2, "len: %s\n%s" % (len(rows), sout))
     self.failIf(rows[1].strip(), sout)
     self.assertTrue(rows[0].split()[0] == "A", sout)
     self.assertTrue(rows[0].split()[1] == "B", sout)
     self.assertTrue(rows[0].split()[2] == "C", sout)
示例#6
0
 def test_spaces(self):
     rows = []
     rows.append(["Campaign ID", "Campaign Name", "Bulkmail ID", "Bulkmail Name"])
     rows.append([180,"PartnersDec172012NewsletterBase",13,"BulkSPDec172012NewsletterFreeAccred"])
     rows.append([180,"PartnersDec172012NewsletterBase",13,"foofoo"])
     rows.append(["    leadingspaces","PartnersDec172012NewsletterBase",13,"foofoo"])
     
     sout = printrows.sprint_rows_as_text(rows)
     self.assertTrue(sout, sout)
     cols = self._check_col_widths(sout)
     self.assertTrue(cols, cols)
     for line in sout.strip().split("\n")[2:]:
         self._check_line(cols, line)
示例#7
0
 def test_multiline_fields(self):
     header = ("A\nAA\nAAA", "B", "C", "D", "EEEE\nE\nEE")
     rows = [header,]+[("a", "b", "c", "d", "e"),]
     sout = printrows.sprint_rows_as_text(rows)
     before, after = sout.split("=",1)
     before_lines = before.strip().split("\n")
     self.assertTrue(len(before_lines)==3, repr(before_lines))
     self.assertIn("EEEE", before_lines[0])
     self.assertIn("AAA", before_lines[2])
     self.assertIn("EE", before_lines[2])
     for c in "BCD":
         self.assertIn(c, before_lines[0])
         self.assertNotIn(c, before_lines[1])
         self.assertNotIn(c, before_lines[2])
     
     after_lines = after.split("=")[-1].strip().split("\n")
     self.assertTrue(len(after_lines)==1, repr(after_lines))
示例#8
0
    def test_width(self):
        MAX_LEN = 2+3+4+(2*2)
        MIN_LEN = 2+3+1+(2*2)
        EXPECTED_ROWS = 3
        sout = printrows.sprint_rows_as_text([("A", "B", "C"),
                                               (22, "QQQ", "QQQQ")], 
                                              first_is_header=False)        
        self.assertTrue(sout, sout)
        rows = sout.split("\n")
        self.assertTrue(len(rows)==EXPECTED_ROWS, "len: %s\n%s" % (len(rows), sout))
        self.failIf(rows[EXPECTED_ROWS-1].strip(), sout)

        saw_max = False
        for idx in range(EXPECTED_ROWS-1):
            self.assertTrue(len(rows[idx])<=MAX_LEN, "%s: Expected: %s, Got: %s\n%s" % (idx, MAX_LEN, len(rows[idx]), repr(sout)))
            self.assertTrue(len(rows[idx])>=MIN_LEN, "%s: Expected: %s, Got: %s\n%s" % (idx, MIN_LEN, len(rows[idx]), repr(sout)))
            if len(rows[idx])==MAX_LEN:
                saw_max = True
        self.assertTrue(saw_max)
示例#9
0
    def test_spaces(self):
        rows = []
        rows.append(
            ["Campaign ID", "Campaign Name", "Bulkmail ID", "Bulkmail Name"])
        rows.append([
            180, "PartnersDec172012NewsletterBase", 13,
            "BulkSPDec172012NewsletterFreeAccred"
        ])
        rows.append([180, "PartnersDec172012NewsletterBase", 13, "foofoo"])
        rows.append([
            "    leadingspaces", "PartnersDec172012NewsletterBase", 13,
            "foofoo"
        ])

        sout = printrows.sprint_rows_as_text(rows)
        self.assertTrue(sout, sout)
        cols = self._check_col_widths(sout)
        self.assertTrue(cols, cols)
        for line in sout.strip().split("\n")[2:]:
            self._check_line(cols, line)
示例#10
0
    def test_multiline_fields(self):
        header = ("A\nAA\nAAA", "B", "C", "D", "EEEE\nE\nEE")
        rows = [
            header,
        ] + [
            ("a", "b", "c", "d", "e"),
        ]
        sout = printrows.sprint_rows_as_text(rows)
        before, after = sout.split("=", 1)
        before_lines = before.strip().split("\n")
        self.assertTrue(len(before_lines) == 3, repr(before_lines))
        self.assertIn("EEEE", before_lines[0])
        self.assertIn("AAA", before_lines[2])
        self.assertIn("EE", before_lines[2])
        for c in "BCD":
            self.assertIn(c, before_lines[0])
            self.assertNotIn(c, before_lines[1])
            self.assertNotIn(c, before_lines[2])

        after_lines = after.split("=")[-1].strip().split("\n")
        self.assertTrue(len(after_lines) == 1, repr(after_lines))
示例#11
0
    def test_width(self):
        MAX_LEN = 2 + 3 + 4 + (2 * 2)
        MIN_LEN = 2 + 3 + 1 + (2 * 2)
        EXPECTED_ROWS = 3
        sout = printrows.sprint_rows_as_text([("A", "B", "C"),
                                              (22, "QQQ", "QQQQ")],
                                             first_is_header=False)
        self.assertTrue(sout, sout)
        rows = sout.split("\n")
        self.assertTrue(
            len(rows) == EXPECTED_ROWS, "len: %s\n%s" % (len(rows), sout))
        self.failIf(rows[EXPECTED_ROWS - 1].strip(), sout)

        saw_max = False
        for idx in range(EXPECTED_ROWS - 1):
            self.assertTrue(
                len(rows[idx]) <= MAX_LEN, "%s: Expected: %s, Got: %s\n%s" %
                (idx, MAX_LEN, len(rows[idx]), repr(sout)))
            self.assertTrue(
                len(rows[idx]) >= MIN_LEN, "%s: Expected: %s, Got: %s\n%s" %
                (idx, MIN_LEN, len(rows[idx]), repr(sout)))
            if len(rows[idx]) == MAX_LEN:
                saw_max = True
        self.assertTrue(saw_max)
示例#12
0
 def test_emptyrows(self):
     sout = printrows.sprint_rows_as_text([])
     self.failIf(sout, sout)
示例#13
0
 def test_unicode(self):
      rows = [["A", "B", "C", "D", "E", "F"],
              ['Account', 'Business_Classification_Cleansed__c', u'Business Classification \u2013 Cleansed', 'string(13)', '', '']]
      sout = printrows.sprint_rows_as_text(rows)
      self.assertEqual(len(sout.split("\n")), 4)
      self.assertIn(u'Business Classification \u2013 Cleansed', sout)
示例#14
0
 def test_emptyrows(self):
     sout = printrows.sprint_rows_as_text([])
     self.failIf(sout, sout)