-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read CSV columns from uploaded file (#45)
* column reading utility * file upload * Get a CSV path, either from the CLI or UI * use render.text and reactive.calc together * hardcoded CSV path works * split calc and text: Multiple decorators do not work? * stronger validation of CLI parameter * read csv in Playwright * add a test of arg parsing * Add failing test * look for any shiny error * do not parse if no file present
- Loading branch information
Showing
8 changed files
with
122 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import csv | ||
|
||
|
||
def read_field_names(csv_path): | ||
with open(csv_path, newline="") as csv_handle: | ||
reader = csv.DictReader(csv_handle) | ||
return reader.fieldnames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
fake-column | ||
student_id,class_year,assignment_type,grade | ||
1234,1,quiz,90 | ||
1234,1,quiz,95 | ||
1234,1,exam,85 | ||
6789,2,quiz,70 | ||
6789,2,quiz,100 | ||
6789,2,exam,90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pathlib import Path | ||
from argparse import ArgumentTypeError | ||
|
||
import pytest | ||
|
||
from dp_creator_ii import get_arg_parser, existing_csv | ||
|
||
|
||
def test_help(): | ||
help = ( | ||
get_arg_parser() | ||
.format_help() | ||
# argparse doesn't actually know the name of the script | ||
# and inserts the name of the running program instead. | ||
.replace("__main__.py", "dp-creator-ii") | ||
.replace("pytest", "dp-creator-ii") | ||
# Text is different under Python 3.9: | ||
.replace("optional arguments:", "options:") | ||
) | ||
print(help) | ||
|
||
readme_md = (Path(__file__).parent.parent.parent / "README.md").read_text() | ||
assert help in readme_md | ||
|
||
|
||
def test_arg_validation_no_file(): | ||
with pytest.raises(ArgumentTypeError, match="No such file: no-such-file"): | ||
existing_csv("no-such-file") | ||
|
||
|
||
def test_arg_validation_not_csv(): | ||
with pytest.raises(ArgumentTypeError, match='Must have ".csv" extension:'): | ||
existing_csv(Path(__file__).parent / "fixtures" / "fake.ipynb") | ||
|
||
|
||
def test_arg_validation_works(): | ||
path = existing_csv(Path(__file__).parent / "fixtures" / "fake.csv") | ||
assert path.name == "fake.csv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.