-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ttimbers/feat-read-data
laying out plans for test and creating test objects
- Loading branch information
Showing
9 changed files
with
111 additions
and
3 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,15 @@ | ||
def read_zip(url, directory): | ||
""" | ||
Read a zip file from the given URL and extract its contents to the specified directory. | ||
Parameters: | ||
---------- | ||
url : str | ||
The URL of the zip file to be read. | ||
directory : str | ||
The directory where the contents of the zip file will be extracted. | ||
Returns: | ||
------- | ||
None | ||
""" |
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,9 @@ | ||
## How to run the test suite | ||
|
||
### Preparation of test zip files | ||
The test zip files used in `test_read_zip.py` were genereated | ||
by running the `generate_test_zip_files.py` script in the `tests` directory. | ||
These files need to exist in the remote GitHub repository for the tests to pass. | ||
If for some reason they go missing from the remote repository, | ||
we can re-run the `generate_test_zip_files.py` script to re-generate them | ||
and then push them to the remote repository. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,43 @@ | ||
import os | ||
import zipfile | ||
import shutil | ||
|
||
# Create a directory named 'subdir' | ||
os.makedirs('subdir', exist_ok=True) | ||
|
||
# Create 'test1.txt' and write "test data" to it | ||
with open('test1.txt', 'w') as file: | ||
file.write('test data') | ||
|
||
# Create 'test2.csv' and write "test data" to it | ||
with open('test2.csv', 'w') as file: | ||
file.write('test,data') | ||
|
||
# Create 'test3.txt' inside 'subdir' and write "test data" to it | ||
with open('subdir/test3.txt', 'w') as file: | ||
file.write('test data') | ||
|
||
# Case 1 - Create a zip file containing 'test1.txt' and 'test2.csv' | ||
with zipfile.ZipFile('files_txt_csv.zip', 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
zipf.write('test1.txt') | ||
zipf.write('test2.csv') | ||
|
||
# Case 2 - Create a zip file containing 'test1.txt', test2.csv and 'subdir/test2.txt' | ||
with zipfile.ZipFile('files_txt_subdir.zip', 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
zipf.write('test1.txt') | ||
zipf.write('test2.csv') | ||
zipf.write('subdir/test3.txt') | ||
|
||
# Case 3 - Create an empty zip file | ||
with zipfile.ZipFile('empty.zip', 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
pass | ||
|
||
# Clean up the files and directories created | ||
test_files = ['test1.txt', 'test2.csv'] | ||
|
||
for file in test_files: | ||
if os.path.exists(file): | ||
os.remove(file) | ||
|
||
if os.path.exists("subdir"): | ||
shutil.rmtree("subdir") |
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,42 @@ | ||
import pytest | ||
import os | ||
import shutil | ||
|
||
# Test files setup | ||
# setup empty directory for data files to be downloaded to | ||
if not os.path.exists('test_zip_data1'): | ||
os.makedirs('test_zip_data1') | ||
|
||
# setup directory that contains a file for data files to be downloaded to | ||
if not os.path.exists('test_zip_data2'): | ||
os.makedirs('test_zip_data2') | ||
with open('test_zip_data2/test3.txt', 'w') as file: | ||
pass # The 'pass' statement does nothing, creating an empty file | ||
|
||
# test read_zip function can download and extract a zip file containing files | ||
# and subdirectories containing files | ||
def test_read_zip_function(): | ||
# add tests here | ||
|
||
|
||
# test read_zip function throws an error if the zip file is empty | ||
def test_read_zip_error_on_empty(): | ||
# add tests here | ||
|
||
|
||
# test read_zip function throws an error if the input URL is invalid | ||
# (e.g., points to a non-existent file or a non-zip file) | ||
def test_read_zip_error_on_invalid_url(): | ||
# add tests here | ||
|
||
|
||
# test read_zip function throws an error | ||
# if the directory path provided does not exist | ||
def test_read_zip_error_on_missing_dir(): | ||
# add tests here | ||
|
||
|
||
# clean up data directory | ||
if os.path.exists("subdir"): | ||
shutil.rmtree("subdir") | ||
|