File: mocking.py

package info (click to toggle)
jupyter-core 4.7.1-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 612 kB
  • sloc: python: 1,606; makefile: 167; sh: 77; javascript: 1
file content (36 lines) | stat: -rw-r--r-- 777 bytes parent folder | download
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
"""General mocking utilities"""

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import sys
from unittest.mock import patch


class MultiPatch(object):
    def __init__(self, *patchers):
        self.patchers = patchers
    
    def __enter__(self):
        for p in self.patchers:
            p.start()
    
    def __exit__(self, *args):
        for p in self.patchers:
            p.stop()

darwin = MultiPatch(
    patch.object(os, 'name', 'posix'),
    patch.object(sys, 'platform', 'darwin'),
)

linux = MultiPatch(
    patch.object(os, 'name', 'posix'),
    patch.object(sys, 'platform', 'linux2'),
)

windows = MultiPatch(
    patch.object(os, 'name', 'nt'),
    patch.object(sys, 'platform', 'win32'),
)