Example #1
0
  def _prep_data(cls, table_id, row_ids, columns):
    def sort(col):
      return [v for r, v in sorted(zip(row_ids, col))]

    sorted_data = actions.TableData(table_id, sorted(row_ids),
                                    {c: sort(col) for c, col in columns.iteritems()})
    return actions.encode_objects(testutil.replace_nans(sorted_data))
Example #2
0
    def assertEqualActionGroups(self, observed, expected):
        """
    Compare grouped doc actions, reporting differences with a customized diff
    (a bit more readable than unittest's usual diff).
    """
        # Do some clean up on the observed data.
        observed = testutil.replace_nans(observed)

        # Convert observed and expected actions into a comparable form.
        for k in self.action_group_action_fields:
            if k in observed:
                observed[k] = [get_comparable_repr(v) for v in observed[k]]
            if k in expected:
                expected[k] = [get_comparable_repr(v) for v in expected[k]]

        if observed != expected:
            o_lines = self._formatActionGroup(observed)
            e_lines = self._formatActionGroup(expected)
            self.fail(("Observed out actions not as expected:\n") + "\n".join(
                difflib.unified_diff(e_lines,
                                     o_lines,
                                     n=3,
                                     lineterm="",
                                     fromfile="expected",
                                     tofile="observed")))
Example #3
0
 def dump_data(self):
     """
 Prints a dump of all engine data, for help in writing / debugging tests.
 """
     output = {t: self.engine.fetch_table(t) for t in self.engine.schema}
     output = testutil.replace_nans(output)
     output = actions.encode_objects(output)
     print(''.join(self._getEngineDataLines(output)))
Example #4
0
  def assertCorrectEngineData(self, expected_data):
    """
    Verifies that the data engine contains the same data as the given expected data,
    which should be a dictionary mapping table names to TableData objects.
    """
    expected_output = actions.decode_objects(expected_data)

    meta_tables = self.engine.fetch_table("_grist_Tables")
    output = {t: self.engine.fetch_table(t) for t in meta_tables.columns["tableId"]}
    output = testutil.replace_nans(output)

    self.assertEqualDocData(output, expected_output)
Example #5
0
 def getFullEngineData(self):
     return testutil.replace_nans(
         {t: self.engine.fetch_table(t)
          for t in self.engine.tables})