File: util.py

package info (click to toggle)
pytest-multihost 3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: python: 801; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#
# Copyright (C) 2013  Red Hat
# Copyright (C) 2014  pytest-multihost contributors
# See COPYING for license
#

import tempfile
import shutil


def check_config_dict_empty(dct, name):
    """Ensure that no keys are left in a configuration dict"""
    if dct:
        raise ValueError('Extra keys in confuguration for %s: %s' %
                         (name, ', '.join(dct)))


def shell_quote(bytestring):
    """Quotes a bytestring for the Bash shell"""
    return b"'" + bytestring.replace(b"'", b"'\\''") + b"'"


class TempDir(object):
    """Handle for a temporary directory that's deleted on garbage collection"""
    def __init__(self):
        self.path = tempfile.mkdtemp(prefix='multihost_tests.')

    def __del__(self):
        shutil.rmtree(self.path)