def test_parse(): from pgtoolkit.service import parse lines = dedent( """\ [service0] host=myhost port=5432 user=toto [service1] host=myhost1 port=5432 dbname=myapp """ ).splitlines() services = parse(lines, source="in-memory") assert 2 == len(services) assert "pgtoolkit" not in repr(services) service0 = services["service0"] assert "service0" == service0.name assert "myhost" == service0.host assert "service0" in repr(service0)
def test_parse_file(mocker): from pgtoolkit.service import parse m = mocker.mock_open() try: mocker.patch("builtins.open", m) except Exception: mocker.patch("__builtin__.open", m) services = parse("filename") assert m.called services.save() m = mocker.Mock() try: mocker.patch("configparser.ConfigParser.write", new_callable=m) except Exception: mocker.patch("ConfigParser.ConfigParser.write", new_callable=m) assert m.called
def test_parse(): from pgtoolkit.service import parse lines = dedent("""\ [service0] host=myhost port=5432 user=toto [service1] host=myhost1 port=5432 dbname=myapp """).splitlines() services = parse(lines, source='in-memory') assert 2 == len(services) assert 'pgtoolkit' not in repr(services) service0 = services['service0'] assert 'service0' == service0.name assert 'myhost' == service0.host assert 'service0' in repr(service0)