File: conftest.py

package info (click to toggle)
bcbio 1.2.9-4
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 36,792 kB
  • sloc: python: 45,766; sh: 209; makefile: 159; xml: 129
file content (39 lines) | stat: -rw-r--r-- 904 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
30
31
32
33
34
35
36
37
38
39

class DummyCM(object):
    """Explicit structure of a context manager.
    Allows to monkey-patch context managers defined through
    @contextmanager decorator.

    value: holds whatever the context manager should yield.
    """
    value = None

    def __init__(self, *args, **kwargs):
        pass

    def __enter__(self):
        return self

    def __exit__(self, *args, **kwargs):
        pass

    def __getattr__(self, attr):
        return self.value.__getattribute__(attr)


class BaseTx(DummyCM, str):
    def __iadd__(self, other):
        """support for += operator to make os.path.join work
        with the value yielded by the dummy context manager"""
        return self.value + other

    def __str__(self):
        return self.value


class DummyTxTmpdir(BaseTx):
    value = 'foo'  # path that dummy tx_tmpdir "yields"


class DummyFileTransaction(BaseTx):
    value = 'tx_file'