|
5 | 5 | from pathlib import Path
|
6 | 6 |
|
7 | 7 | import numpy as np
|
| 8 | +import palletjack |
8 | 9 | import pandas as pd
|
9 | 10 | import pyogrio
|
10 | 11 | import pytest
|
11 | 12 | from arcgis import geometry
|
12 | 13 | from pandas import testing as tm
|
13 | 14 |
|
14 |
| -import palletjack |
15 |
| - |
16 | 15 |
|
17 | 16 | @pytest.fixture(scope="module") #: only call this once per module
|
18 | 17 | def iris():
|
@@ -85,61 +84,6 @@ def test_rename_columns_for_agol_moves_underscore_before_leading_digits_to_end(s
|
85 | 84 | assert renamed == {"_1TestName:": "TestName__1"}
|
86 | 85 |
|
87 | 86 |
|
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 |
| - |
143 | 87 | class TestRetry:
|
144 | 88 |
|
145 | 89 | 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)
|
795 | 739 |
|
796 | 740 | class TestCheckFieldsMatch:
|
797 | 741 |
|
| 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 | + |
798 | 794 | def test_check_live_and_new_field_types_match_normal(self, mocker):
|
799 | 795 | new_df = pd.DataFrame(
|
800 | 796 | {
|
|
0 commit comments