File: __init__.py

package info (click to toggle)
python-queuelib 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: python: 1,034; sh: 8; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 959 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
37
import shutil
import tempfile
import unittest
from pathlib import Path


class QueuelibTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.tmpdir = tempfile.mkdtemp(prefix="queuelib-tests-")
        self.qpath: Path = self.tempfilename()
        self.qdir = self.mkdtemp()

    def tearDown(self) -> None:
        shutil.rmtree(self.qdir)
        shutil.rmtree(self.tmpdir)

    def tempfilename(self) -> Path:
        with tempfile.NamedTemporaryFile(dir=self.tmpdir) as nf:
            return Path(nf.name)

    def mkdtemp(self) -> str:
        return tempfile.mkdtemp(dir=self.tmpdir)


def track_closed(cls):
    """Wraps a queue class to track down if close() method was called"""

    class TrackingClosed(cls):
        def __init__(self, *a, **kw):
            super().__init__(*a, **kw)
            self.closed = False

        def close(self):
            super().close()
            self.closed = True

    return TrackingClosed