-
Notifications
You must be signed in to change notification settings - Fork 4
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
Coverage update #42
Coverage update #42
Changes from 2 commits
d592a28
e60512e
0893f3a
76040b8
7e4480c
d8e34b5
bee2b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[run] | ||
parallel = True | ||
command_line = -m pytest | ||
source = | ||
data_request_api/stable | ||
|
||
[report] | ||
fail_under = 50 | ||
exclude_lines = | ||
if __name__ == "__main__": |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import os | ||
|
||
import dreq_content as dc | ||
from . import dreq_content as dc | ||
import pytest | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ dependencies: | |
- requests | ||
- bs4 | ||
- coverage | ||
- pytest |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ran for me, and the html report Does the Can this file and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to add the six package as dependency but I may be wrong as we are in python3. Did you have issues with it when you run the API the first time? The htmlcov directory can be customed through .coveragerc. I will change the default value to a place in the tests directory in my branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have checked and I change the locations of the temporary files and .coveragerc too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be done once #39 will be merged, change the default cache for pytest in the pyproj.toml file : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests are quite long because some scripts make the splitting from the single and the several databases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have just tested the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
# -*- coding: utf-8 -*- | ||
|
||
coverage erase | ||
|
||
coverage run | ||
# To be moved before once tests are fixed | ||
set -e | ||
coverage run --parallel-mode scripts/database_transformation.py --output_dir="test" --dreq_export_version="raw" | ||
coverage run --parallel-mode scripts/database_transformation.py --output_dir="test" --dreq_export_version="release" | ||
coverage run --parallel-mode scripts/export_dreq_lists_json.py --all_opportunities "v1.0" "result.json" | ||
rm -f result.json | ||
coverage run --parallel-mode scripts/workflow_example.py | ||
rm -f "requested_v1.0.json" "requested_raw.json" | ||
coverage run --parallel-mode scripts/workflow_example_2.py --output_dir="test" --dreq_export_version="raw" | ||
coverage run --parallel-mode scripts/workflow_example_2.py --output_dir="test" --dreq_export_version="release" | ||
|
||
coverage combine | ||
|
||
coverage html |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ openpyxl | |
pandas | ||
requests | ||
bs4 | ||
coverage | ||
coverage | ||
pytest |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,46 +8,68 @@ | |
|
||
import os | ||
import sys | ||
import argparse | ||
import tempfile | ||
|
||
add_paths = ['../data_request_api/stable/content/dreq_api/', | ||
'../data_request_api/stable'] | ||
for path in add_paths: | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
import dreq_content as dc | ||
from content.dump_transformation import transform_content | ||
from query.data_request import DataRequest | ||
from utilities.tools import write_json_output_file_content | ||
from utilities.logger import change_log_file, change_log_level | ||
|
||
import data_request_api.stable.content.dreq_api.dreq_content as dc | ||
from data_request_api.stable.content.dump_transformation import transform_content, get_transformed_content | ||
from data_request_api.stable.query.data_request import DataRequest | ||
from data_request_api.stable.utilities.tools import write_json_output_file_content | ||
from data_request_api.stable.utilities.logger import change_log_file, change_log_level | ||
|
||
# Set up log file (default to stdout) and log level | ||
change_log_file(default=True) | ||
change_log_level("debug") | ||
|
||
### Step 1: Get the content of the DR | ||
# Define content version to be used | ||
# use_dreq_version = 'v1.0alpha' | ||
# use_dreq_version = "first_export" | ||
# use_dreq_version = 'new_export_15Oct2024' | ||
use_dreq_version = "v1.0" | ||
use_export_versions = ["raw", "release"] | ||
output_directory = f'{dc._dreq_res}/{use_dreq_version}' | ||
for use_export_version in use_export_versions: | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--log_level", default="info", help="Log level") | ||
parser.add_argument("--dreq_version", default="latest_stable", help="Version to be used") | ||
parser.add_argument("--dreq_export_version", default="release", help="Export version to be used") | ||
parser.add_argument("--use_consolidation", default=False, help="Should content consolidation be used?") | ||
parser.add_argument("--output_dir", choices=["default", "test", "customed"], default="default", | ||
help="Output directory management") | ||
parser.add_argument("--output_dir_customed", default=None, help="Customed output directory to be used") | ||
args = parser.parse_args() | ||
|
||
|
||
def database_transformation(output_dir, dreq_version="latest_stable", dreq_export_version="release", | ||
use_consolidation=False): | ||
# Download specified version of data request content (if not locally cached) | ||
content = dc.load(use_dreq_version, export=use_export_version, consolidate=False) | ||
versions = dc.retrieve(dreq_version, export=dreq_export_version, consolidate=use_consolidation) | ||
|
||
### Step 2: Transform content into DR and VS | ||
data_request, vocabulary_server = transform_content(content, version=use_dreq_version) | ||
for (version, content) in versions.items(): | ||
# Load the content | ||
content = dc.load(version, export=dreq_export_version, consolidate=use_consolidation) | ||
|
||
### Step 3: Write down the two files | ||
DR_file = os.path.sep.join([output_directory, f"DR_{use_export_version}_content.json"]) | ||
VS_file = os.path.sep.join([output_directory, f"VS_{use_export_version}_content.json"]) | ||
write_json_output_file_content(DR_file, data_request) | ||
write_json_output_file_content(VS_file, vocabulary_server) | ||
# Transform content into DR and VS | ||
data_request, vocabulary_server = transform_content(content, version=dreq_version) | ||
|
||
DR = DataRequest.from_separated_inputs(DR_input=DR_file, VS_input=VS_file) | ||
# Write down the two files | ||
DR_file = os.path.sep.join([output_dir, version, f"DR_{dreq_export_version}_content.json"]) | ||
VS_file = os.path.sep.join([output_dir, version, f"VS_{dreq_export_version}_content.json"]) | ||
write_json_output_file_content(DR_file, data_request) | ||
write_json_output_file_content(VS_file, vocabulary_server) | ||
|
||
# Test that the two files do not produce issues with the API | ||
DR = DataRequest.from_separated_inputs(DR_input=DR_file, VS_input=VS_file) | ||
|
||
|
||
# Set up log file (default to stdout) and log level | ||
change_log_file(default=True) | ||
change_log_level(args.log_level) | ||
|
||
if args.output_dir in ["default", "customed"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this implement this feature:
from the PR description? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it only deals with the files derived from the export file. |
||
if args.output_dir in ["default", ]: | ||
output_dir = dc._dreq_res | ||
elif args.output_dir_customed is not None: | ||
output_dir = args.output_dir_customed | ||
else: | ||
raise ValueError("If --output_dir='customed', --output_dir_customed should be defined with a not None value.") | ||
|
||
database_transformation(output_dir=output_dir, dreq_version=args.dreq_version, | ||
dreq_export_version=args.dreq_export_version, use_consolidation=args.use_consolidation) | ||
elif args.output_dir in ["test", ]: | ||
with tempfile.TemporaryDirectory() as output_dir: | ||
database_transformation(output_dir=output_dir, dreq_version=args.dreq_version, | ||
dreq_export_version=args.dreq_export_version, use_consolidation=args.use_consolidation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be better:
? in case this script moves