forked from dbfixtures/pytest-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
141 lines (107 loc) · 4.83 KB
/
plugin.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (C) 2016 by Clearcode <http://clearcode.cc>
# and associates (see AUTHORS).
# This file is part of pytest-postgresql.
# pytest-dbfixtures is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# pytest-postgresql is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
"""Plugin module of pytest-postgresql."""
from tempfile import gettempdir
from pytest_postgresql import factories
from _pytest.config.argparsing import Parser
_help_executable = "Path to PostgreSQL executable"
_help_host = "Host at which PostgreSQL will accept connections"
_help_port = "Port at which PostgreSQL will accept connections"
_help_user = "PostgreSQL username"
_help_password = "PostgreSQL password"
_help_options = "PostgreSQL connection options"
_help_startparams = "Starting parameters for the PostgreSQL"
_help_logsprefix = "Prefix for the log files"
_help_unixsocketdir = "Location of the socket directory"
_help_dbname = "Default database name"
_help_load = "Dotted-style or entrypoint-style path to callable or path to SQL File"
_help_postgres_options = "Postgres executable extra parameters. Passed via the -o option to pg_ctl"
_help_use_database = "Use provided database, do not create/drop it"
def pytest_addoption(parser: Parser) -> None:
"""Configure options for pytest-postgresql."""
parser.addini(
name="postgresql_exec", help=_help_executable, default="/usr/lib/postgresql/13/bin/pg_ctl"
)
parser.addini(name="postgresql_host", help=_help_host, default="127.0.0.1")
parser.addini(
name="postgresql_port",
help=_help_port,
default=None,
)
parser.addini(name="postgresql_user", help=_help_user, default="postgres")
parser.addini(name="postgresql_password", help=_help_password, default=None)
parser.addini(name="postgresql_options", help=_help_options, default="")
parser.addini(name="postgresql_startparams", help=_help_startparams, default="-w")
parser.addini(name="postgresql_logsprefix", help=_help_logsprefix, default="")
parser.addini(name="postgresql_unixsocketdir", help=_help_unixsocketdir, default=gettempdir())
parser.addini(name="postgresql_dbname", help=_help_dbname, default="tests")
parser.addini(name="postgresql_use_database", type="bool", help=_help_use_database, default=False)
parser.addini(name="postgresql_load", type="pathlist", help=_help_load, default=None)
parser.addini(name="postgresql_postgres_options", help=_help_postgres_options, default="")
parser.addoption(
"--postgresql-exec",
action="store",
metavar="path",
dest="postgresql_exec",
help=_help_executable,
)
parser.addoption(
"--postgresql-host",
action="store",
dest="postgresql_host",
help=_help_host,
)
parser.addoption("--postgresql-port", action="store", dest="postgresql_port", help=_help_port)
parser.addoption("--postgresql-user", action="store", dest="postgresql_user", help=_help_user)
parser.addoption(
"--postgresql-password", action="store", dest="postgresql_password", help=_help_password
)
parser.addoption(
"--postgresql-options", action="store", dest="postgresql_options", help=_help_options
)
parser.addoption(
"--postgresql-startparams",
action="store",
dest="postgresql_startparams",
help=_help_startparams,
)
parser.addoption(
"--postgresql-logsprefix",
action="store",
dest="postgresql_logsprefix",
help=_help_logsprefix,
)
parser.addoption(
"--postgresql-unixsocketdir",
action="store",
dest="postgresql_unixsocketdir",
help=_help_unixsocketdir,
)
parser.addoption(
"--postgresql-dbname", action="store", dest="postgresql_dbname", help=_help_dbname
)
parser.addoption(
"--postgresql-use-database", action="store_true", dest="postgresql_use_database",
help=_help_use_database
)
parser.addoption("--postgresql-load", action="append", dest="postgresql_load", help=_help_load)
parser.addoption(
"--postgresql-postgres-options",
action="store",
dest="postgresql_postgres_options",
help=_help_postgres_options,
)
postgresql_proc = factories.postgresql_proc()
postgresql_noproc = factories.postgresql_noproc()
postgresql = factories.postgresql("postgresql_proc")