Skip to content

Commit f87f4c5

Browse files
committed
chore: pass ruff linting tests
1 parent d60ec25 commit f87f4c5

File tree

7 files changed

+65
-72
lines changed

7 files changed

+65
-72
lines changed

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[tool.ruff]
22
line-length = 120
33
ignore = ["E501"]
4+
[tool.ruff.lint.per-file-ignores]
5+
"tests/*.py" = ["F841"]
46
[tool.black]
57
line-length = 120
68
[tool.pytest.ini_options]

src/palletjack/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import locale
77

8-
from . import extract, load, transform, utils
9-
from .errors import IntFieldAsFloatError, TimezoneAwareDatetimeError
8+
from . import extract, load, transform, utils # noqa: F401
9+
from .errors import IntFieldAsFloatError, TimezoneAwareDatetimeError # noqa: F401
1010

1111
#: If the locale is not set explicitly, set it to the system default for text to number conversions
1212
if not locale.getlocale(locale.LC_NUMERIC)[0]:

src/palletjack/load.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
import json
66
import logging
77
import shutil
8-
import sys
98
import warnings
109
from datetime import datetime
1110
from pathlib import Path
12-
from tempfile import TemporaryDirectory
1311

1412
import arcgis
15-
import geopandas as gpd
1613
import numpy as np
1714
import pandas as pd
1815
import pyogrio
19-
from arcgis.features import GeoAccessor, GeoSeriesAccessor
16+
from arcgis.features import GeoAccessor, GeoSeriesAccessor # noqa: F401
2017

2118
from palletjack import utils
2219

src/palletjack/transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import arcgis
1010
import pandas as pd
11-
from arcgis import GeoAccessor, GeoSeriesAccessor
11+
from arcgis import GeoAccessor, GeoSeriesAccessor # noqa: F401
1212

1313
from palletjack import utils
1414

tests/test_extract.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ def test_get_object_ids_raises_on_key_error(self, mocker):
976976
class_mock.envelope_params = None
977977
class_mock.where_clause = "1=1"
978978

979-
with pytest.raises(RuntimeError, match=re.escape(f"Could not get object IDs from foo.bar")):
979+
with pytest.raises(RuntimeError, match=re.escape("Could not get object IDs from foo.bar")):
980980
record_count = extract.ServiceLayer.get_object_ids(class_mock)
981981

982982
def test_get_object_ids_returns_empty_list_on_no_oids(self, mocker):
@@ -1239,8 +1239,8 @@ def test_credential_values(self):
12391239

12401240
assert loader.client_secret == "1"
12411241
assert loader.client_id == "2"
1242-
assert loader.username == None
1243-
assert loader.password == None
1242+
assert loader.username is None
1243+
assert loader.password is None
12441244

12451245
@pytest.mark.parametrize("is_sandbox,access_token_url,query_url", url_template_test_data)
12461246
def test_url_template_substitutions(self, is_sandbox, access_token_url, query_url):

tests/test_load.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import datetime
21
import json
32
import logging
43
import re
5-
import sys
64
import urllib
75
from pathlib import Path
86

@@ -11,7 +9,7 @@
119
import pandas.testing as tm
1210
import pyogrio
1311
import pytest
14-
from arcgis import GeoAccessor, GeoSeriesAccessor
12+
from arcgis import GeoAccessor, GeoSeriesAccessor # noqa: F401
1513
from palletjack import load
1614

1715

@@ -384,7 +382,7 @@ def test_truncate_and_load_append_fails_save_old_true(self, mocker, caplog):
384382
)
385383

386384
updater_mock._upload_data.assert_called_once_with(new_dataframe, upsert=False)
387-
assert f"Append failed. Data saved to bar_path" in caplog.text
385+
assert "Append failed. Data saved to bar_path" in caplog.text
388386

389387
def test_truncate_and_load_append_fails_save_old_false(self, mocker, caplog):
390388
caplog.set_level(logging.DEBUG)
@@ -407,7 +405,7 @@ def test_truncate_and_load_append_fails_save_old_false(self, mocker, caplog):
407405

408406
updater_mock._upload_data.assert_called_once_with(new_dataframe, upsert=False)
409407

410-
assert f"Append failed. Old data not saved (save_old set to False)" in caplog.text
408+
assert "Append failed. Old data not saved (save_old set to False)" in caplog.text
411409

412410
def test_truncate_and_load_calls_field_checkers(self, mocker, caplog):
413411

tests/test_utils.py

+53-57
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
from pathlib import Path
66

77
import numpy as np
8+
import palletjack
89
import pandas as pd
910
import pyogrio
1011
import pytest
1112
from arcgis import geometry
1213
from pandas import testing as tm
1314

14-
import palletjack
15-
1615

1716
@pytest.fixture(scope="module") #: only call this once per module
1817
def iris():
@@ -85,61 +84,6 @@ def test_rename_columns_for_agol_moves_underscore_before_leading_digits_to_end(s
8584
assert renamed == {"_1TestName:": "TestName__1"}
8685

8786

88-
class TestCheckFieldsMatch:
89-
90-
def test_check_fields_match_normal(self, mocker):
91-
mock_fl = mocker.Mock()
92-
mock_fl.properties.fields = [
93-
{"name": "Foo"},
94-
{"name": "Bar"},
95-
]
96-
df = pd.DataFrame(columns=["Foo", "Bar"])
97-
98-
palletjack.utils.check_fields_match(mock_fl, df)
99-
100-
def test_check_fields_match_raises_error_on_extra_new_field(self, mocker):
101-
mock_fl = mocker.Mock()
102-
mock_fl.properties.fields = [
103-
{"name": "Foo"},
104-
{"name": "Bar"},
105-
]
106-
df = pd.DataFrame(columns=["Foo", "Bar", "Baz"])
107-
108-
with pytest.raises(RuntimeError) as exc_info:
109-
palletjack.utils.check_fields_match(mock_fl, df)
110-
111-
assert (
112-
exc_info.value.args[0]
113-
== "New dataset contains the following fields that are not present in the live dataset: {'Baz'}"
114-
)
115-
116-
def test_check_fields_match_ignores_new_shape_field(self, mocker):
117-
mock_fl = mocker.Mock()
118-
mock_fl.properties.fields = [
119-
{"name": "Foo"},
120-
{"name": "Bar"},
121-
]
122-
df = pd.DataFrame(columns=["Foo", "Bar", "SHAPE"])
123-
124-
palletjack.utils.check_fields_match(mock_fl, df)
125-
126-
def test_check_fields_match_warns_on_missing_new_field(self, mocker, caplog):
127-
mock_fl = mocker.Mock()
128-
mock_fl.properties.fields = [
129-
{"name": "Foo"},
130-
{"name": "Bar"},
131-
{"name": "Baz"},
132-
]
133-
df = pd.DataFrame(columns=["Foo", "Bar"])
134-
135-
palletjack.utils.check_fields_match(mock_fl, df)
136-
137-
assert (
138-
"New dataset does not contain the following fields that are present in the live dataset: {'Baz'}"
139-
in caplog.text
140-
)
141-
142-
14387
class TestRetry:
14488

14589
def test_retry_returns_on_first_success(self, mocker):
@@ -795,6 +739,58 @@ def test_fix_numeric_empty_strings_handles_single_missing_shape_info_field(self)
795739

796740
class TestCheckFieldsMatch:
797741

742+
def test_check_fields_match_normal(self, mocker):
743+
mock_fl = mocker.Mock()
744+
mock_fl.properties.fields = [
745+
{"name": "Foo"},
746+
{"name": "Bar"},
747+
]
748+
df = pd.DataFrame(columns=["Foo", "Bar"])
749+
750+
palletjack.utils.check_fields_match(mock_fl, df)
751+
752+
def test_check_fields_match_raises_error_on_extra_new_field(self, mocker):
753+
mock_fl = mocker.Mock()
754+
mock_fl.properties.fields = [
755+
{"name": "Foo"},
756+
{"name": "Bar"},
757+
]
758+
df = pd.DataFrame(columns=["Foo", "Bar", "Baz"])
759+
760+
with pytest.raises(RuntimeError) as exc_info:
761+
palletjack.utils.check_fields_match(mock_fl, df)
762+
763+
assert (
764+
exc_info.value.args[0]
765+
== "New dataset contains the following fields that are not present in the live dataset: {'Baz'}"
766+
)
767+
768+
def test_check_fields_match_ignores_new_shape_field(self, mocker):
769+
mock_fl = mocker.Mock()
770+
mock_fl.properties.fields = [
771+
{"name": "Foo"},
772+
{"name": "Bar"},
773+
]
774+
df = pd.DataFrame(columns=["Foo", "Bar", "SHAPE"])
775+
776+
palletjack.utils.check_fields_match(mock_fl, df)
777+
778+
def test_check_fields_match_warns_on_missing_new_field(self, mocker, caplog):
779+
mock_fl = mocker.Mock()
780+
mock_fl.properties.fields = [
781+
{"name": "Foo"},
782+
{"name": "Bar"},
783+
{"name": "Baz"},
784+
]
785+
df = pd.DataFrame(columns=["Foo", "Bar"])
786+
787+
palletjack.utils.check_fields_match(mock_fl, df)
788+
789+
assert (
790+
"New dataset does not contain the following fields that are present in the live dataset: {'Baz'}"
791+
in caplog.text
792+
)
793+
798794
def test_check_live_and_new_field_types_match_normal(self, mocker):
799795
new_df = pd.DataFrame(
800796
{

0 commit comments

Comments
 (0)