File: test_context_manager.py

package info (click to toggle)
python-secretstorage 3.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: python: 762; makefile: 11; sh: 8
file content (25 lines) | stat: -rw-r--r-- 874 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
# Tests for SecretStorage
# Author: Dmitry Shachnev, 2019
# License: 3-clause BSD, see LICENSE file

# This file tests using secretstorage.dbus_init() function
# together with contextlib.closing context manager.

import unittest
from contextlib import closing

from secretstorage import check_service_availability, dbus_init
from secretstorage.collection import get_any_collection


class ContextManagerTest(unittest.TestCase):
    """``dbus_init()`` should work fine with ``contextlib.closing``
    context manager."""

    def test_closing_context_manager(self) -> None:
        with closing(dbus_init()) as connection:
            self.assertTrue(check_service_availability(connection))
            collection = get_any_collection(connection)
            self.assertIsNotNone(collection)
            label = collection.get_label()
            self.assertIsNotNone(label)