Skip to content

Commit

Permalink
encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bencevans committed Mar 26, 2024
1 parent 8669e22 commit cb87b0e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion camtrapdp/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def from_csv(file_path: str) -> List["Deployment"]:
List of deployment objects.
"""

with open(file_path, "r") as file:
with open(file_path, "r", encoding='utf-8-sig') as file:
reader = DictReader(file)
return [Deployment(**row) for row in reader]

Expand Down
2 changes: 1 addition & 1 deletion camtrapdp/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def from_csv(file_path: str) -> List["Media"]:
List of media objects.
"""

with open(file_path, "r") as file:
with open(file_path, "r", encoding='utf-8-sig') as file:
reader = DictReader(file)
return [Media(**row) for row in reader]

Expand Down
2 changes: 1 addition & 1 deletion camtrapdp/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def from_csv(file_path: str) -> List["Observation"]:
List of observation objects.
"""

with open(file_path, "r") as file:
with open(file_path, "r", encoding="utf-8-sig") as file:
reader = DictReader(file)
return [Observation(**row) for row in reader]

Expand Down
6 changes: 3 additions & 3 deletions camtrapdp/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def test_read_from_csv():

def test_write_to_csv():
deployments = Deployment.from_csv("fixtures/deployments.csv")
with NamedTemporaryFile(mode="w", delete=False) as file:
with NamedTemporaryFile(mode="w", delete=True) as file:
Deployment.to_csv(deployments, file.name)
with open("fixtures/deployments.csv", "r") as original:
with open(file.name, "r") as new:
with open("fixtures/deployments.csv", "r", encoding='utf-8-sig') as original:
with open(file.name, "r", encoding='utf-8-sig') as new:
assert original.read() == new.read()


Expand Down
6 changes: 3 additions & 3 deletions camtrapdp/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def test_read_from_csv():

def test_write_to_csv():
media = Media.from_csv("fixtures/media.csv")
with NamedTemporaryFile(mode="w", delete=False) as file:
with NamedTemporaryFile(mode="w", delete=True) as file:
Media.to_csv(media, file.name)
with open("fixtures/media.csv", "r") as original:
with open(file.name, "r") as new:
with open("fixtures/media.csv", "r", encoding='utf-8-sig') as original:
with open(file.name, "r", encoding='utf-8-sig') as new:
assert original.read() == new.read()


Expand Down
7 changes: 4 additions & 3 deletions camtrapdp/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@


def test_read_from_csv():
print(Observation.__annotations__)
observations = Observation.from_csv("fixtures/observations.csv")
print(observations)
assert len(observations) == 549


def test_write_to_csv():
observations = Observation.from_csv("fixtures/observations.csv")
with NamedTemporaryFile(mode="w", delete=False) as file:
with NamedTemporaryFile(mode="w", delete=True) as file:
Observation.to_csv(observations, file.name)
with open("fixtures/observations.csv", "r") as original:
with open(file.name, "r") as new:
with open("fixtures/observations.csv", "r", encoding="utf-8-sig") as original:
with open(file.name, "r", encoding="utf-8-sig") as new:
assert original.read() == new.read()


Expand Down

0 comments on commit cb87b0e

Please sign in to comment.