Skip to content

Commit

Permalink
[#4781] Convert reads and writes in project fixture to text/utf-8 enc…
Browse files Browse the repository at this point in the history
…oding
  • Loading branch information
gshank committed Feb 24, 2022
1 parent 42d5812 commit 6f90cc3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Re-format codebase (except tests) using pre-commit hooks ([#3195](https://github.com/dbt-labs/dbt-core/issues/3195), [#4697](https://github.com/dbt-labs/dbt-core/pull/4697))
- Add deps module README ([#4686](https://github.com/dbt-labs/dbt-core/pull/4686/))
- Initial conversion of tests to pytest ([#4690](https://github.com/dbt-labs/dbt-core/issues/4690), [#4691](https://github.com/dbt-labs/dbt-core/pull/4691))
- Fix errors in Windows for tests/functions ([#4781](https://github.com/dbt-labs/dbt-core/issues/4781), [#4767](https://github.com/dbt-labs/dbt-core/pull/4767))

Contributors:
- [@NiallRees](https://github.com/NiallRees) ([#4447](https://github.com/dbt-labs/dbt-core/pull/4447))
Expand Down
17 changes: 11 additions & 6 deletions core/dbt/tests/fixtures/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def dbt_profile_data(unique_schema, database_host):
def profiles_yml(profiles_root, dbt_profile_data):
os.environ["DBT_PROFILES_DIR"] = str(profiles_root)
path = os.path.join(profiles_root, "profiles.yml")
with open(path, "w") as fp:
with open(path, "w", encoding="utf-8") as fp:
fp.write(yaml.safe_dump(dbt_profile_data))
yield dbt_profile_data
del os.environ["DBT_PROFILES_DIR"]
Expand All @@ -138,7 +138,8 @@ def dbt_project_yml(project_root, project_config_update, logs_dir):
if project_config_update:
project_config.update(project_config_update)
runtime_config_file = project_root.join("dbt_project.yml")
runtime_config_file.write(yaml.safe_dump(project_config))
with open(runtime_config_file, "w", encoding="utf-8") as fp:
fp.write(yaml.safe_dump(project_config))


# Fixture to provide packages as either yaml or dictionary
Expand All @@ -155,7 +156,8 @@ def packages_yml(project_root, packages):
data = packages
else:
data = yaml.safe_dump(packages)
project_root.join("packages.yml").write(data)
with open(project_root.join("packages.yml"), "w", encoding="utf-8") as fp:
fp.write(data)


# Fixture to provide selectors as either yaml or dictionary
Expand All @@ -172,7 +174,8 @@ def selectors_yml(project_root, selectors):
data = selectors
else:
data = yaml.safe_dump(selectors)
project_root.join("selectors.yml").write(data)
with open(project_root.join("selectors.yml"), "w", encoding="utf-8") as fp:
fp.write(data)


# This creates an adapter that is used for running test setup and teardown,
Expand Down Expand Up @@ -205,13 +208,15 @@ def write_project_files(project_root, dir_name, file_dict):
def write_project_files_recursively(path, file_dict):
for name, value in file_dict.items():
if name.endswith(".sql") or name.endswith(".csv") or name.endswith(".md"):
path.join(name).write(value)
with open(path.join(name), "w", encoding="utf-8") as fp:
fp.write(value)
elif name.endswith(".yml") or name.endswith(".yaml"):
if isinstance(value, str):
data = value
else:
data = yaml.safe_dump(value)
path.join(name).write(data)
with open(path.join(name), "w", encoding="utf-8") as fp:
fp.write(data)
else:
write_project_files_recursively(path.mkdir(name), value)

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/jaffle_shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def seeds():
dir_path = os.path.dirname(os.path.realpath(__file__))
for file_name in ("raw_customers.csv", "raw_orders.csv", "raw_payments.csv"):
path = os.path.join(dir_path, "jaffle_shop_data", file_name)
with open(path, "rb") as fp:
with open(path, "r") as fp:
seeds[file_name] = fp.read()
return seeds

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/basic/test_copy_uppercase.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def models():
def seeds(test_data_dir):
# Read seed file and return
path = os.path.join(test_data_dir, "seed-initial.csv")
with open(path, "rb") as fp:
with open(path, "r") as fp:
seed_csv = fp.read()
return {"seed.csv": seed_csv}
return {}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/basic/test_simple_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def models():
def seeds(test_data_dir):
# Read seed file and return
path = os.path.join(test_data_dir, "seed-initial.csv")
with open(path, "rb") as fp:
with open(path, "r") as fp:
seed_csv = fp.read()
return {"seed.csv": seed_csv}
return {}
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/basic/test_simple_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ def seeds(test_data_dir):
# Read seed file and return
seeds = {"properties.yml": properties_yml}
path = os.path.join(test_data_dir, "seed-initial.csv")
with open(path, "rb") as fp:
with open(path, "r") as fp:
seed_csv = fp.read()
seeds["users.csv"] = seed_csv
path = os.path.join(test_data_dir, "summary_expected.csv")
with open(path, "rb") as fp:
with open(path, "r") as fp:
summary_csv = fp.read()
seeds["summary_expected.csv"] = summary_csv
return seeds
Expand Down

0 comments on commit 6f90cc3

Please sign in to comment.