Generate a set of URLs to test given configured URLs plus additional driver names. Given: .. sourcecode:: text --dburi postgresql://db1 \ --dburi postgresql://db2 \ --dburi postgresql://db2 \ --dbdriver=psycopg2 --dbdriver=asyncpg Noting that th
(db_urls, extra_drivers)
| 116 | |
| 117 | |
| 118 | def generate_db_urls(db_urls, extra_drivers): |
| 119 | class="st">"""Generate a set of URLs to test given configured URLs plus additional |
| 120 | driver names. |
| 121 | |
| 122 | Given: |
| 123 | |
| 124 | .. sourcecode:: text |
| 125 | |
| 126 | --dburi postgresql://db1 \ |
| 127 | --dburi postgresql://db2 \ |
| 128 | --dburi postgresql://db2 \ |
| 129 | --dbdriver=psycopg2 --dbdriver=asyncpg |
| 130 | |
| 131 | Noting that the default postgresql driver is psycopg2, the output |
| 132 | would be: |
| 133 | |
| 134 | .. sourcecode:: text |
| 135 | |
| 136 | postgresql+psycopg2://db1 |
| 137 | postgresql+asyncpg://db1 |
| 138 | postgresql+psycopg2://db2 |
| 139 | postgresql+psycopg2://db3 |
| 140 | |
| 141 | That is, for the driver in a --dburi, we want to keep that and use that |
| 142 | driver for each URL it&class="cm">#x27;s part of . For a driver that is only |
| 143 | in --dbdrivers, we want to use it just once for one of the URLs. |
| 144 | for a driver that is both coming from --dburi as well as --dbdrivers, |
| 145 | we want to keep it in that dburi. |
| 146 | |
| 147 | Driver specific query options can be specified by added them to the |
| 148 | driver name. For example, to a sample option the asyncpg: |
| 149 | |
| 150 | .. sourcecode:: text |
| 151 | |
| 152 | --dburi postgresql://db1 \ |
| 153 | --dbdriver=asyncpg?some_option=a_value |
| 154 | |
| 155 | class="st">""" |
| 156 | urls = set() |
| 157 | |
| 158 | backend_to_driver_we_already_have = collections.defaultdict(set) |
| 159 | |
| 160 | urls_plus_dialects = [ |
| 161 | (url_obj, url_obj.get_dialect()) |
| 162 | for url_obj in [sa_url.make_url(db_url) for db_url in db_urls] |
| 163 | ] |
| 164 | |
| 165 | for url_obj, dialect in urls_plus_dialects: |
| 166 | class="cm"># use get_driver_name instead of dialect.driver to account for |
| 167 | class="cm"># class="st">"_async" virtual drivers like oracledb and psycopg |
| 168 | driver_name = url_obj.get_driver_name() |
| 169 | backend_to_driver_we_already_have[dialect.name].add(driver_name) |
| 170 | |
| 171 | backend_to_driver_we_need = {} |
| 172 | |
| 173 | for url_obj, dialect in urls_plus_dialects: |
| 174 | backend = dialect.name |
| 175 | dialect.load_provisioning() |
nothing calls this directly
no test coverage detected