How to use the placebo.pill.Pill function in placebo

To help you get started, we’ve selected a few placebo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloud-custodian / cloud-custodian / tests / zpill.py View on Github external
return result
    if isinstance(obj, bytes):
        return obj.decode('utf8')

    # Raise a TypeError if the object isn't recognized
    raise TypeError("Type not serializable")


placebo.pill.serialize = serialize
placebo.pill.deserialize = deserialize

# END PLACEBO MONKEY
##########################################################################


class BluePill(pill.Pill):

    def playback(self):
        super(BluePill, self).playback()
        self._avail = self.get_available()

    def get_available(self):
        return set(
            [
                os.path.join(self.data_path, n)
                for n in fnmatch.filter(os.listdir(self.data_path), "*.json")
            ]
        )

    def get_next_file_path(self, service, operation):
        fn = super(BluePill, self).get_next_file_path(service, operation)
        # couple of double use cases
github cloud-custodian / cloud-custodian / tests / zpill.py View on Github external
fn = super(BluePill, self).get_next_file_path(service, operation)
        # couple of double use cases
        if fn in self._avail:
            self._avail.remove(fn)
        else:
            print("\ndouble use %s\n" % fn)
        return fn

    def stop(self):
        result = super(BluePill, self).stop()
        if self._avail:
            print("Unused json files \n %s" % ("\n".join(sorted(self._avail))))
        return result


class ZippedPill(pill.Pill):

    def __init__(self, path, prefix=None, debug=False):
        super(ZippedPill, self).__init__(prefix, debug)
        self.path = path
        self._used = set()
        self.archive = None

    def playback(self):
        self.archive = zipfile.ZipFile(self.path, "r")
        self._files = set(self.archive.namelist())
        return super(ZippedPill, self).playback()

    def record(self):
        self.archive = zipfile.ZipFile(self.path, "a", zipfile.ZIP_DEFLATED)
        self._files = set()
github garnaat / placebo / placebo / __init__.py View on Github external
def attach(session, data_path, prefix=None, debug=False):
    pill = Pill(prefix=prefix, debug=debug)
    pill.attach(session, data_path)
    return pill