Skip to content

Commit 3fc0d51

Browse files
committed
additional uses of pathlib after merging with main
1 parent c6aec45 commit 3fc0d51

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# add these directories to sys.path here. If the directory is relative to the
1313
# documentation root, use Path.absolute() to make it absolute, like shown here.
1414
#
15-
import os
1615
import sys
1716
from pathlib import Path
1817

parsons/catalist/catalist.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import base64
77
import logging
8-
import os
98
import tempfile
109
import time
1110
import urllib
@@ -380,15 +379,15 @@ def load_matches(self, id: str) -> Table:
380379
with ZipFile(temp_file_zip) as zf:
381380
zf.extractall(path=temp_dir)
382381

383-
filepath = os.listdir(temp_dir)[0]
382+
filepath = next(Path(temp_dir).iterdir())
384383

385-
result = Table.from_csv(Path(temp_dir) / filepath, delimiter="\t")
384+
result = Table.from_csv(str(filepath), delimiter="\t")
386385
return result
387386

388387
def validate_table(self, table: Table, template_id: str = "48827") -> None:
389388
"""Validate table structure and contents."""
390389
if not template_id == "48827":
391-
logger.warn(f"No validator implemented for template {template_id}.")
390+
logger.warning(f"No validator implemented for template {template_id}.")
392391
return
393392

394393
expected_table_columns = [

parsons/databases/sqlite/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def query_with_connection(
111111
if return_values and cursor.description:
112112
temp_file = files.create_temp_file()
113113

114-
with open(temp_file, "wb") as f:
114+
with Path(temp_file).open(mode="wb") as f:
115115
# Grab the header
116116
header = [i[0] for i in cursor.description]
117117
pickle.dump(header, f)

parsons/google/google_bigquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def copy_direct(
849849
)
850850

851851
tmpfile_path = tbl.to_csv()
852-
with open(tmpfile_path, mode="rb") as tmpfile:
852+
with Path(tmpfile_path).open(mode="rb") as tmpfile:
853853
load_job = self.client.load_table_from_file(
854854
tmpfile,
855855
destination=self.get_table_ref(table_name=table_name),

test/test_catalist/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def mock_miscellaneous(mocker) -> Generator[MagicMock, None, None]:
4040
magic_mock = MagicMock()
4141

4242
mocker.patch("parsons.catalist.catalist.ZipFile", new=magic_mock)
43-
mocker.patch("parsons.catalist.catalist.os", new=magic_mock)
43+
mocker.patch("parsons.catalist.catalist.Path", new=magic_mock)
4444
mocker.patch("parsons.catalist.catalist.Table", new=magic_mock)
4545

4646
yield mocker

test/test_scytl/test_scytl.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import csv
2-
import os
32
import unittest
43
from pathlib import Path
54

@@ -198,9 +197,9 @@ def _mock_responses(self, m: requests_mock.Mocker):
198197
text=(_DIR / "GA_114729_296262_county_election_settings.json").read_text(),
199198
)
200199

201-
for file in os.listdir(_DIR / "mock_responses"):
202-
file_url = f"https://results.enr.clarityelections.com/{file}".replace("_", "/")
203-
m.get(file_url, content=Path(_DIR / "mock_responses" / file).read_bytes())
200+
for file in (_DIR / "mock_responses").iterdir():
201+
file_url = f"https://results.enr.clarityelections.com/{file.name}".replace("_", "/")
202+
m.get(file_url, content=file.read_bytes())
204203

205204
mock_summary_csv_url = scytl.SUMMARY_CSV_ZIP_URL_TEMPLATE.format(
206205
administrator=TEST_STATE,

0 commit comments

Comments
 (0)