Skip to content

Commit b4b0b4d

Browse files
committed
Use system independent paths for test comparisons
Uses pathlib's PurePath to represent every multi-component path across the unit tests, allowing them to pass on both Linux/MacOS and Windows
1 parent cc7043a commit b4b0b4d

13 files changed

+79
-34
lines changed

oxen/tests/conftest.py

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

44
import uuid
55
import os
6+
from pathlib import PurePath
67

78
from oxen import Repo, RemoteRepo
89

@@ -151,7 +152,9 @@ def house_prices_local_repo_fully_committed(house_prices_local_repo_no_commits):
151152

152153
@pytest.fixture
153154
def empty_remote_repo():
154-
repo_name = f"py-ox/test_repo_{str(uuid.uuid4())}"
155+
156+
repo_str = str(PurePath("py-ox", "test_repo"))
157+
repo_name = f"{repo_str}_{str(uuid.uuid4())}"
155158
repo = RemoteRepo(repo_name, host=TEST_HOST, scheme=TEST_SCHEME)
156159
repo.create(empty=True)
157160
yield repo
@@ -162,7 +165,7 @@ def empty_remote_repo():
162165
def celeba_local_repo_one_image_committed(celeba_local_repo_no_commits):
163166
repo = celeba_local_repo_no_commits
164167

165-
image_file = "images/1.jpg"
168+
image_file = str(PurePath("images", "1.jpg"))
166169
full_path = os.path.join(repo.path, image_file)
167170
repo.add(full_path)
168171
repo.commit("Adding first image")

oxen/tests/test_add.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
from oxen import Repo
4-
4+
from pathlib import PurePath
55

66
def test_add(shared_datadir):
77
repo_dir = os.path.join(shared_datadir, "CelebA")
@@ -15,8 +15,12 @@ def test_add(shared_datadir):
1515
added_files = staged_data.added_files()
1616
added_files.sort()
1717

18+
test_path = PurePath("annotations", "test.csv")
19+
train_path = PurePath("annotations", "train.csv")
20+
labels_path = PurePath("annotations", "labels.txt")
21+
1822
assert set(added_files) == {
19-
"annotations/test.csv",
20-
"annotations/train.csv",
21-
"annotations/labels.txt",
22-
}
23+
str(test_path),
24+
str(train_path),
25+
str(labels_path),
26+
}

oxen/tests/test_commit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2+
from pathlib import PurePath
23

34

45
def test_commit_one_file(celeba_local_repo_no_commits):
56
repo = celeba_local_repo_no_commits
67

78
# oxen add
8-
image_file = "images/1.jpg"
9+
image_file = str(PurePath("images", "1.jpg"))
910
full_path = os.path.join(repo.path, image_file)
1011
repo.add(full_path)
1112

oxen/tests/test_data_frame.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import os
22

33
import pandas as pd
4+
from pathlib import PurePath
45

56
from oxen import DataFrame, RemoteRepo, Workspace
67

78

89
def test_data_frame_crud(celeba_remote_repo_fully_pushed):
910
_, remote_repo = celeba_remote_repo_fully_pushed
1011

11-
new_row = {"file": "images/123456.png", "hair_color": "purple"}
12+
image = str(PurePath("images", "123456.png"))
13+
new_row = {"file": str(image), "hair_color": "purple"}
1214

15+
train_path = str(PurePath("annotations", "train.csv"))
1316
df = DataFrame(
1417
remote_repo.identifier,
15-
"annotations/train.csv",
18+
train_path,
1619
host="localhost:3000",
1720
scheme="http",
1821
)
@@ -41,11 +44,13 @@ def test_data_frame_crud(celeba_remote_repo_fully_pushed):
4144
def test_data_frame_commit(celeba_remote_repo_fully_pushed):
4245
_, remote_repo = celeba_remote_repo_fully_pushed
4346

44-
new_row = {"file": "images/123456.png", "hair_color": "purple"}
47+
image = str(PurePath("images", "123456.png"))
48+
new_row = {"file": image, "hair_color": "purple"}
4549

50+
train_path = str(PurePath("annotations", "train.csv"))
4651
df = DataFrame(
4752
remote_repo.identifier,
48-
"annotations/train.csv",
53+
train_path,
4954
host="localhost:3000",
5055
scheme="http",
5156
)
@@ -72,14 +77,16 @@ def test_remove_data_frame_row(
7277
workspace = Workspace(remote_repo, "main")
7378
print("Created workspace ", workspace)
7479

75-
new_row = {"file": "images/123456.png", "hair_color": "purple"}
80+
image = str(PurePath("images", "123456.png"))
81+
new_row = {"file": image, "hair_color": "purple"}
7682

7783
assert len(workspace.status().added_files()) == 0
7884
workspace.add(file_path, "csvs")
7985
workspace.commit("add train.csv")
8086

87+
train_path = str(PurePath("csvs", "train.csv"))
8188
workspace = Workspace(remote_repo, "main")
82-
df = DataFrame(workspace, "csvs/train.csv")
89+
df = DataFrame(workspace, train_path)
8390
_width, og_height = df.size()
8491

8592
row_id = df.insert_row(new_row)

oxen/tests/test_fsspec_backend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fsspec
33
import pandas as pd
44

5+
from pathlib import PurePath
56
from oxen import RemoteRepo
67

78

@@ -17,10 +18,13 @@ def test_fsspec_read_file(
1718
fs = fsspec.filesystem(
1819
"oxen", namespace=namespace, repo=repo_name, host=host, scheme=scheme
1920
)
20-
with fs.open("images/1.jpg", mode="rb") as f:
21+
22+
image = str(PurePath("images", "1.jpg"))
23+
with fs.open(image, mode="rb") as f:
2124
remote_image_file = f.read()
2225

23-
with open(os.path.join(shared_datadir, "CelebA/images/1.jpg"), "rb") as f:
26+
celeb_path = str(PurePath("CelebA", "images", "1.jpg"))
27+
with open(os.path.join(shared_datadir, celeb_path), "rb") as f:
2428
assert remote_image_file == f.read()
2529

2630

oxen/tests/test_remote_repo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
2+
from pathlib import PurePath
33

44
def test_remote_repo_exists(empty_remote_repo):
55
exists = True
@@ -8,7 +8,8 @@ def test_remote_repo_exists(empty_remote_repo):
88

99
def test_remote_repo_add(celeba_remote_repo_one_image_pushed, shared_datadir):
1010
_local_repo, remote_repo = celeba_remote_repo_one_image_pushed
11-
full_path = os.path.join(shared_datadir, "ChatBot/examples.tsv")
11+
examples_path = str(PurePath("ChatBot", "examples.tsv"))
12+
full_path = os.path.join(shared_datadir, examples_path)
1213
remote_repo.add(full_path)
1314
status = remote_repo.status()
1415
added_files = status.added_files()

oxen/tests/test_workspace_add.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import os
22
from oxen import RemoteRepo
33
from oxen import Workspace
4+
from pathlib import PurePath
45

56

67
def test_workspace_add_single_file(
78
celeba_remote_repo_one_image_pushed: RemoteRepo, shared_datadir
89
):
9-
full_path = os.path.join(shared_datadir, "CelebA/images/1.jpg")
10+
images_path = str(PurePath("CelebA", "images", "1.jpg"))
11+
full_path = os.path.join(shared_datadir, images_path)
1012

1113
_, remote_repo = celeba_remote_repo_one_image_pushed
1214
workspace = Workspace(remote_repo, "main", "test-workspace")
@@ -15,13 +17,15 @@ def test_workspace_add_single_file(
1517
status = workspace.status()
1618
added_files = status.added_files()
1719

18-
assert added_files == ["a-folder/1.jpg"]
20+
added_path = str(PurePath("a-folder", "1.jpg"))
21+
assert added_files == [added_path]
1922

2023

2124
def test_workspace_add_root_dir(
2225
celeba_remote_repo_one_image_pushed: RemoteRepo, shared_datadir
2326
):
24-
full_path = os.path.join(shared_datadir, "CelebA/images/3.jpg")
27+
images_path = str(PurePath("CelebA", "images", "3.jpg"))
28+
full_path = os.path.join(shared_datadir, images_path)
2529

2630
_, remote_repo = celeba_remote_repo_one_image_pushed
2731
workspace = Workspace(remote_repo, "main", "test-workspace")

oxen/tests/test_workspace_add_to_branch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from oxen import Workspace
3+
from pathlib import PurePath
34

45

56
def test_workspace_add_to_branch(celeba_remote_repo_one_image_pushed, shared_datadir):
@@ -9,7 +10,9 @@ def test_workspace_add_to_branch(celeba_remote_repo_one_image_pushed, shared_dat
910

1011
workspace = Workspace(remote_repo, "newbranch")
1112

12-
full_path = os.path.join(shared_datadir, "CelebA/images/1.jpg")
13+
image = str(PurePath("CelebA", "images", "1.jpg"))
14+
15+
full_path = os.path.join(shared_datadir, image)
1316
workspace.add(full_path)
1417
status = workspace.status()
1518

oxen/tests/test_workspace_commit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import pytest
33
from oxen import RemoteRepo, Workspace
4+
from pathlib import PurePath
45

56

67
def test_commit_one_file(
@@ -9,7 +10,8 @@ def test_commit_one_file(
910
_, remote_repo = celeba_remote_repo_one_image_pushed
1011
# 1 commit pushed in setup
1112
assert len(remote_repo.log()) == 1
12-
full_path = os.path.join(shared_datadir, "CelebA/images/1.jpg")
13+
images_path = str(PurePath("CelebA", "images", "1.jpg"))
14+
full_path = os.path.join(shared_datadir, images_path)
1315
workspace = Workspace(remote_repo, "main")
1416
workspace.add(full_path)
1517
workspace.commit("a commit message!")

oxen/tests/test_workspace_data_frame_add_row.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
import os
44
from oxen import Workspace, DataFrame
5+
from pathlib import PurePath
56

67

78
def test_workspace_df_add_row_success(
@@ -15,13 +16,16 @@ def test_workspace_df_add_row_success(
1516
workspace.add(file_path, "csvs")
1617
workspace.commit("add train.csv")
1718

18-
new_row = {"file": "images/123456.png", "hair_color": "purple"}
19-
remote_df = DataFrame(workspace, "csvs/train.csv")
19+
images_path = str(PurePath("images", "123456.png"))
20+
new_row = {"file": images_path, "hair_color": "purple"}
21+
22+
train_path = str(PurePath("csvs", "train.csv"))
23+
remote_df = DataFrame(workspace, train_path)
2024
remote_df.insert_row(new_row)
2125
workspace.commit("add row to train.csv")
2226

2327
# Download the file
24-
remote_repo.download("csvs/train.csv", file_path)
28+
remote_repo.download(train_path, file_path)
2529

2630
# Check the new file
2731
new_df = pd.read_csv(file_path)
@@ -42,10 +46,13 @@ def test_remote_df_add_row_invalid_schema(
4246
file_path = os.path.join(shared_datadir, "CelebA", "annotations", "train.csv")
4347
# df = pd.read_csv(file_path)
4448

45-
new_row = {"gahfile": "images/123456.png", "hair_color": "purple"}
49+
images_path = str(PurePath("images", "123456.png"))
50+
new_row = {"gahfile": images_path, "hair_color": "purple"}
4651

4752
workspace.add(file_path, "csvs")
4853
workspace.commit("add train.csv")
49-
remote_df = DataFrame(workspace, "csvs/train.csv")
54+
55+
train_path = str(PurePath("csvs", "train.csv"))
56+
remote_df = DataFrame(workspace, train_path)
5057
with pytest.raises(ValueError):
5158
remote_df.insert_row(new_row)

0 commit comments

Comments
 (0)