File: test_messaging.py

package info (click to toggle)
alembic 1.16.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,216 kB
  • sloc: python: 39,738; makefile: 100; sh: 5
file content (31 lines) | stat: -rw-r--r-- 996 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
from io import StringIO

from alembic.testing import eq_
from alembic.testing import mock
from alembic.testing.fixtures import TestBase
from alembic.util.messaging import msg
from alembic.util.messaging import obfuscate_url_pw


class MessagingTest(TestBase):
    def test_msg_wraps(self):
        buf = StringIO()
        with (
            mock.patch("sys.stdout", buf),
            mock.patch("alembic.util.messaging.TERMWIDTH", 10),
        ):
            msg("AAAAAAAAAAAAAAAAA")
        eq_(
            str(buf.getvalue()).splitlines(),
            [
                "  AAAAAAAA",  # initial indent 10 chars before wrapping
                "  AAAAAAAA",  # subsequent indent 10 chars before wrapping
                "  A",  # subsequent indent with remainining chars
            ],
        )

    def test_current_obfuscate_password(self):
        eq_(
            obfuscate_url_pw("postgresql://scott:tiger@localhost/test"),
            "postgresql://scott:***@localhost/test",
        )