I have encountered a pattern in a public git repository* hosted by Udacity that I can't find any documentation on:
The folder structure is:
|-- quiz
| |-- m1
| |-- L2
| |-- quiz_tests.py
| |-- tests.py
| |-- quiz notebook.ipynb
|-- tests.py
notebook.ipynb imports
import quiz_tests
-> which imports tests.py
-> which only contains the following:
../../../tests.py
(with no quotation marks)
When I try to run this it gives me an import error:
cannot import name 'project_test' from 'tests'
What is this pattern and how can I make it work?
Thanks in advance!
*unfortunately the issue asking about the same question got closed without answer
Code:
notebook.ipynb
import quiz_tests
def calculate_returns(close):
return None
quiz_tests.test_calculate_returns(calculate_returns)
quiz_tests.py
from collections import OrderedDict
import numpy as np
import pandas as pd
from tests1 import project_test, generate_random_tickers, generate_random_dates, assert_output
@project_test
def test_calculate_returns(fn):
tickers = generate_random_tickers(5)
dates = generate_random_dates(6)
fn_inputs = {
'close': pd.DataFrame(
[
[21.050810483942833, 17.013843810658827, 10.984503755486879, 11.248093428369392, 12.961712733997235],
[15.63570258751384, 14.69054309070934, 11.353027688995159, 475.74195118202061, 11.959640427803022],
],
dates, tickers)}
fn_correct_outputs = OrderedDict([
(
'returns',
pd.DataFrame(
[
[np.nan, np.nan, np.nan, np.nan, np.nan],
[-0.25723988, -0.13655355, 0.03354944, 41.29534136, -0.07731018],
dates, tickers))])
assert_output(fn, fn_inputs, fn_correct_outputs)
tests.py
../../../tests.py