Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganizes tests and adds a few initial tests for the data side #226

Merged
merged 16 commits into from
Oct 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revises and renames file for testing scrape
lfashby committed Oct 11, 2020
commit 0ec4b847c7de5369f51d05516dca6acf727b7586
34 changes: 34 additions & 0 deletions tests/test_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a file moved from a different directory?

Is it common for this sort of thing to go in an __init__.py file? It seems like that's usually just reserved for aliasing and imports. One alternative would be to have something called like test_setup.py or something in this directory and have __init__.py pull it in.

import shutil

from contextlib import contextmanager

_TESTS_DIR = os.path.dirname(
os.path.dirname(os.path.realpath(__file__))
)
_TSV_PATH = f"{_TESTS_DIR}/tsv"
_PHONES_PATH = f"{_TESTS_DIR}/phones"

def write_files_dummy_phones_files(key: str, dialect: str):
with open(
f"{_PHONES_PATH}/{key}_{dialect}phonetic.phones",
"w",
) as f1:
f1.write("a")
with open(
f"{_PHONES_PATH}/{key}_{dialect}phonemic.phones",
"w",
) as f2:
f2.write("a")


@contextmanager
def handle_dummy_files(phones: bool, key: str, dialect: str):
os.mkdir(_TSV_PATH)
os.mkdir(_PHONES_PATH)
print("IN CONTENXT MAANGER")
if phones:
write_files_dummy_phones_files(key, dialect)
yield _TSV_PATH
shutil.rmtree(_TSV_PATH)
shutil.rmtree(_PHONES_PATH)
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@

from data.src.scrape import _build_scraping_config


PARENT_DIR = os.path.dirname(os.getcwd())
from . import handle_dummy_files

# "mul" should be a future-proof iso639 code to test with.
# "mul" is resolved to "Multiple Languages" by iso639 package,
@@ -33,46 +32,27 @@
{"key": "mul"},
"test_",
False,
[
"mul_test_phonetic.tsv",
"mul_test_phonemic.tsv",
],
["mul_test_phonetic.tsv", "mul_test_phonemic.tsv",],
),
# Standard
(
{"key": "mul"},
"",
False,
[
"mul_phonetic.tsv",
"mul_phonemic.tsv",
],
["mul_phonetic.tsv", "mul_phonemic.tsv",],
),
],
)
def test_something(config_settings, dialect_suffix, phones, expected_file_name):
tsv_path = f"{PARENT_DIR}/tsv"
phones_path = f"{PARENT_DIR}/phones"
os.mkdir(tsv_path)
os.mkdir(phones_path)

if phones:
with open(
f"{phones_path}/{config_settings['key']}_{dialect_suffix}phonetic.phones",
"w",
) as f1:
f1.write("a")
with open(
f"{phones_path}/{config_settings['key']}_{dialect_suffix}phonemic.phones",
"w",
) as f2:
f2.write("a")
_build_scraping_config(
config_settings=config_settings, dialect_suffix=dialect_suffix
)
contents = os.listdir(tsv_path)
shutil.rmtree(tsv_path)
shutil.rmtree(phones_path)
def test_file_creation(
config_settings, dialect_suffix, phones, expected_file_name
):
with handle_dummy_files(
phones, config_settings["key"], dialect_suffix
) as dummy_tsv_path:
_build_scraping_config(
config_settings=config_settings, dialect_suffix=dialect_suffix
)
tsv_contents = os.listdir(dummy_tsv_path)

for produced_file in contents:
for produced_file in tsv_contents:
assert produced_file in expected_file_name