コード例 #1
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
 def verifyCsvWrite(self, s):
     """Verifies csv writer can write the given grid correctly.
     """
     grid = ZincReader(s).readGrid()
     csv_out = CsvWriter.gridToString(grid)
     #print("csv_out: '%s'" % csv_out)
     # for now just verify this is valid csv
     #json.loads(csv_out)
     reader = csv.reader(StringIO.StringIO(csv_out))
     #print("csv after parse:")
     for i, row in enumerate(reader):
         self.assertEqual(len(row), grid.num_cols())
         #print(row)
     self.assertEqual(i, grid.num_rows())
コード例 #2
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
 def verifyJsonWrite(self, s):
     """Verifies json writer can write the given grid correctly.
     """
     grid = ZincReader(s).readGrid()
     json_out = JsonWriter.gridToString(grid)
     #print("json_out: '%s'" % json_out)
     # for now just verify this is valid json
     json.loads(json_out)
コード例 #3
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
    def verifyGrid(self, s, meta, cols, rows):
        # normalize nulls
        if not meta:
            meta = HDict.EMPTY
        for i in range(len(cols)):
            if not cols[i]:
                cols[i] = HDict.EMPTY

        # read from zinc
        grid = ZincReader(s).readGrid()
        #self.verifyGridEq(grid, meta, cols, rows)

        # write grid and verify we can parse that too
        writestr = ZincWriter.gridToString(grid)
        print("orig: '%s'" % s)
        print("new: '%s'" % writestr)
        write_grid = ZincReader(writestr).readGrid()
        self.verifyGridEq(write_grid, meta, cols, rows)
コード例 #4
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
    def test_multigrid(self):
        """Test multigrid read
        """

        grids = ZincReader(multigrid).readGrids()
        self.assertEqual(len(grids), 2)

        self.verifyGrid(multigrid,
                        None,
                        [ ("header_label", HDictBuilder().toDict()), ("header_value", HDictBuilder().toDict()),
                          ("type", HDictBuilder().toDict())],
                        [
                        [ HStr.make("KPIs"),
                            HStr.make("RECENT"),
                            HStr.make("list"),
                        ]
                        ]
        )

        self.verifyMultiGrid(multigrid, 0,
                        None,
                        [ ("header_label", HDictBuilder().toDict()), ("header_value", HDictBuilder().toDict()),
                          ("type", HDictBuilder().toDict())],
                        [
                            [ HStr.make("KPIs"),
                              HStr.make("RECENT"),
                              HStr.make("list"),
                              ]
                        ]
        )

        self.verifyMultiGrid(multigrid, 1,
                             None,
                             [ ("value", HDictBuilder().toDict()), ("label", HDictBuilder().toDict()),
                               ],
                             [
                                [ HStr.make("1000 KWH"),
                                   HStr.make("KWH USED"),
                                ],
                                [ HStr.make("100 KW"),
                                  HStr.make("KW PEAK"),
                                  ],
                                [ HStr.make("$199.95"),
                                  HStr.make("ENERGY CHARGE"),
                                  ],
                                [ HStr.make("$199.95"),
                                  HStr.make("ENERGY CHARGE"),
                                  ],
                             ]
        )
コード例 #5
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
    def verifyMultiGrid(self, s, grid_index, meta, cols, rows):
        """Verify given grid within multigrid.
        """
        # normalize nulls
        if not meta:
            meta = HDict.EMPTY
        for i in range(len(cols)):
            if not cols[i]:
                cols[i] = HDict.EMPTY

        # read from zinc
        grids = ZincReader(s).readGrids()
        self.assertLess(grid_index, len(grids))
        grid = grids[grid_index]
        #self.verifyGridEq(grid, meta, cols, rows)

        # write grid and verify we can parse that too
        writestr = ZincWriter.gridToString(grid)
        writestrmulti = ZincWriter.gridsToString(grids)
        print("orig: '%s'" % s)
        print("new for multigrid: '%s'" % writestrmulti)
        print("new for single grid: '%s'" % writestr)
        write_grid = ZincReader(writestr).readGrid()
        self.verifyGridEq(write_grid, meta, cols, rows)
コード例 #6
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
    def verifyCsvMultiWrite(self, s):
        """Verifies csv writer can write the given grids correctly.
        """
        grids = ZincReader(s).readGrids()
        csv_out_multi = CsvWriter.gridsToString(grids)
        #print("csv_out_multi: '%s'" % csv_out_multi)
        # cummulative rows/cols:
        row_counts = map(lambda x: x.num_rows(), grids)
        total_rows = reduce(lambda x, y: x+y, row_counts)
        col_counts = map(lambda x: x.num_cols(), grids)
        max_cols = reduce(lambda x, y: max(x, y), col_counts)

        # verify csv after parsing matches number total number of rows + 1, and cols
        reader = csv.reader(StringIO.StringIO(csv_out_multi))
        #print("csv multi after parse:")
        for i, row in enumerate(reader):
            #self.assertEqual(len(row), max_cols)
            #print(row)
            pass
        # i + 1 = csv rows
        grid_count = len(grids)
        csv_total_rows = i + 1
        # grid_count because csv has a header row for each grid and a separator line for each (grid_count-1)
        self.assertEqual(csv_total_rows-2*grid_count+1, total_rows)
コード例 #7
0
ファイル: test_dict.py プロジェクト: techempowers/pyhs
 def verifyZinc(self, s, tags):
     x = ZincReader(s).readDict()
     if len(tags) <= 1:
         self.assertEqual(x, tags)
コード例 #8
0
ファイル: test_zinc.py プロジェクト: techempowers/pyhs
 def test_multigrid_json(self):
     grids = ZincReader(multigrid).readGrids()
     json_out_multi = JsonWriter.gridsToString(grids)
     #print("json_out_multi: '%s'" % json_out_multi)
     # for now just verify this is valid json
     json.loads(json_out_multi)