示例#1
0
def globals_diff(run1, run2, group=None):
    """Take a diff of the globals between two runs.

    Uses the :obj:`labscript-utils:dict_diff` function.

    Args:
        run1 (:obj:`Run`): First Run to compare.
        run2 (:obj:`Run`): Second Run to compare.
        group (str, optional): When `None` (default), compare all groups.
            Otherwise, only compare globals in `group`.

    Returns:
        dict: Dictionary of differences between globals in the form `key:[val1,val2]`
        pairs. Keys unique to either dictionary are returned as `key:[val1,'-']` or
        `key:['-',val2]`.
    """
    return dict_diff(run1.get_globals(group), run2.get_globals(group))
示例#2
0
    def assert_superset(self, other):
        # let's check that we're a superset of the connection table in "other"
        if not isinstance(other, ConnectionTable):
            msg = "Loaded file is not a valid connection table"
            raise TypeError(msg)

        missing = []  # things I don't know exist
        incompat = []  # things that are different from what I expect

        for name, other_connection in other.table.items():
            # does it exist?
            try:
                connection = self.table[name]
            except KeyError:
                missing.append('  ' + name)
            else:
                # is it the same?
                if connection != other_connection:
                    diff = connection.diff(other_connection)
                    msg = '  ' + name + ':\n'
                    for key, (ours, theirs) in diff.items():
                        if isinstance(ours, dict) and isinstance(theirs, dict):
                            msg += '    {}:\n'.format(key)
                            subdiff = dict_diff(ours, theirs)
                            for key, (ours, theirs) in subdiff.items():
                                msg += '      {}: {} != {}'.format(
                                    key, ours, theirs)
                        else:
                            msg += '    {}: {} != {}'.format(key, ours, theirs)
                    incompat.append(msg)

        # construct a human-readable explanation
        errmsg = ""
        if len(missing) > 0:
            errmsg += '\nDevices that do not exist in the connection table:\n  ' + '\n'.join(
                missing)
        if len(incompat) > 0:
            errmsg += '\nDevices with incompatible settings:\n' + '\n'.join(
                incompat)

        # if there is no error message, then everything must be good!
        if errmsg:
            msg = "Cannot execute script as connection tables do not match." + errmsg
            raise Exception(msg)
示例#3
0
 def diff(self, other):
     return dict_diff(self._rowdict, other._rowdict)
示例#4
0
def globals_diff(run1, run2, group=None):
    return dict_diff(run1.get_globals(group), run2.get_globals(group))