Commit dcb7328a authored by Christophe Benz's avatar Christophe Benz
Browse files

Add tests to delete series in TSV and JSONL

parent 070c497f
......@@ -79,7 +79,7 @@ def test_import_jsonl_series(git_repo: git.Repo, dolt_repo_dir: Path):
assert series_row["observations"] == '[["PERIOD","VALUE"],["2000",1]]'
def test_delete_a_series(git_repo: git.Repo, dolt_repo_dir: Path):
def test_delete_a_series_tsv(git_repo: git.Repo, dolt_repo_dir: Path):
git_repo_dir = Path(git_repo.working_dir)
dataset_dir = git_repo_dir / "D1"
......@@ -104,9 +104,66 @@ def test_delete_a_series(git_repo: git.Repo, dolt_repo_dir: Path):
series_row = dolt_repo.sql("select count(*) from series", result_format="csv")[0]
assert series_row["COUNT(*)"] == "1"
series_row = dolt_repo.sql("select * from series limit 1", result_format="csv")[0]
series_row = dolt_repo.sql("select * from series", result_format="csv")[0]
assert series_row["code"] == "S2"
before_last_dolt_commit_id = dolt_repo.sql("select commit_hash from dolt_log order by date", result_format="csv")[
1
]["commit_hash"]
series_row = dolt_repo.sql(
f"select count(*) from series as of '{before_last_dolt_commit_id}'", result_format="csv"
)[0]
assert series_row["COUNT(*)"] == "2"
series_rows = dolt_repo.sql(
f"select * from series as of '{before_last_dolt_commit_id}' order by code", result_format="csv"
)
assert series_rows[0]["code"] == "S1"
assert series_rows[1]["code"] == "S2"
def test_delete_a_series_jsonl(git_repo: git.Repo, dolt_repo_dir: Path):
git_repo_dir = Path(git_repo.working_dir)
dataset_dir = git_repo_dir / "D1"
dataset_dir.mkdir()
dataset_json = {"code": "D1", "name": "Dataset 1"}
add_json_file_to_git_repo(git_repo, dataset_dir / "dataset.json", dataset_json)
series_jsonl = [
{"code": "S1", "observations": [["PERIOD", "VALUE"], ["2000", 1]]},
{"code": "S2", "observations": [["PERIOD", "VALUE"], ["2001", 1.1]]},
]
add_jsonl_file_to_git_repo(git_repo, dataset_dir / "series.jsonl", series_jsonl)
git_repo.index.commit("Add dataset D1")
add_jsonl_file_to_git_repo(git_repo, dataset_dir / "series.jsonl", series_jsonl[1:])
git_repo.index.commit("Remove S1")
import_json_data(git_repo_dir, dolt_repo_dir=dolt_repo_dir)
dolt_repo = Dolt(dolt_repo_dir)
series_row = dolt_repo.sql("select count(*) from series", result_format="csv")[0]
assert series_row["COUNT(*)"] == "1"
series_row = dolt_repo.sql("select * from series", result_format="csv")[0]
assert series_row["code"] == "S2"
before_last_dolt_commit_id = dolt_repo.sql("select commit_hash from dolt_log order by date", result_format="csv")[
1
]["commit_hash"]
series_row = dolt_repo.sql(
f"select count(*) from series as of '{before_last_dolt_commit_id}'", result_format="csv"
)[0]
assert series_row["COUNT(*)"] == "2"
series_rows = dolt_repo.sql(
f"select * from series as of '{before_last_dolt_commit_id}' order by code", result_format="csv"
)
assert series_rows[0]["code"] == "S1"
assert series_rows[1]["code"] == "S2"
def add_json_file_to_git_repo(git_repo: git.Repo, path: Path, data):
data_str = serialize_json(data)
......@@ -114,7 +171,7 @@ def add_json_file_to_git_repo(git_repo: git.Repo, path: Path, data):
def add_jsonl_file_to_git_repo(git_repo: git.Repo, path: Path, data: list):
data_str = "".join(map(serialize_json, data))
data_str = "\n".join(map(serialize_json, data))
add_file_to_git_repo(git_repo, path, data_str)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment