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

Integration tests refactor #3781

Merged
merged 79 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
25d5cc0
generate integration tests report
montezdesousa Dec 14, 2022
2d7b94b
new console report
montezdesousa Dec 14, 2022
469185a
simple run_scripts
montezdesousa Dec 14, 2022
be547fc
move tests script to folder
montezdesousa Dec 15, 2022
ee86829
add skipping
montezdesousa Dec 15, 2022
69d40e5
always display skips
montezdesousa Dec 15, 2022
94a503e
func name
montezdesousa Dec 15, 2022
1d069b7
allow running from relative path
montezdesousa Dec 15, 2022
29e009a
rename some vars and time
montezdesousa Dec 15, 2022
887e6a2
typo
montezdesousa Dec 15, 2022
012876c
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 15, 2022
82cd9d8
change portfolio supress and warning
montezdesousa Dec 15, 2022
70b1480
Merge branch 'feature/integration_tests' of github.com:OpenBB-finance…
montezdesousa Dec 15, 2022
6e38ad8
uncomment economy test
montezdesousa Dec 15, 2022
c132dc8
rename test controller
montezdesousa Dec 15, 2022
e05ff1a
multiprocessing
montezdesousa Dec 15, 2022
4162f35
display test progress and available
montezdesousa Dec 15, 2022
3d88659
rename func
montezdesousa Dec 15, 2022
d783e63
mypy
montezdesousa Dec 15, 2022
2d43db4
should not be here
montezdesousa Dec 15, 2022
04e6f6d
small changes
montezdesousa Dec 16, 2022
57cc99b
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 16, 2022
1c93710
type hinting and docstrings
montezdesousa Dec 16, 2022
dd2597a
Merge branch 'feature/integration_tests' of github.com:OpenBB-finance…
montezdesousa Dec 16, 2022
e5ac5a3
new subprocesses default
montezdesousa Dec 16, 2022
101bd02
forget context and chunksize
montezdesousa Dec 16, 2022
5362c2d
clean len skipt
montezdesousa Dec 16, 2022
8ff4235
small comment
montezdesousa Dec 16, 2022
afa2506
fix subproc default with v
montezdesousa Dec 16, 2022
7d33a90
minor change
montezdesousa Dec 16, 2022
a3252d5
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 16, 2022
efa07c8
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 17, 2022
b131f44
fix path
montezdesousa Dec 17, 2022
0a567b2
better this way
montezdesousa Dec 17, 2022
150e05f
make output visible
montezdesousa Dec 17, 2022
6a1a010
allow only sequential run with verbose mode
montezdesousa Dec 19, 2022
75b491e
change message
montezdesousa Dec 19, 2022
528e44f
detail
montezdesousa Dec 19, 2022
15d4d28
include andrew idea
montezdesousa Dec 19, 2022
a9f7957
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 19, 2022
40adea8
limit multiprocessing to clone version
montezdesousa Dec 20, 2022
c1b7928
fix for package application
montezdesousa Dec 20, 2022
336182b
must be up here
montezdesousa Dec 20, 2022
24d52be
allow verbose with multiprocessing but warn
montezdesousa Dec 20, 2022
e001d39
update readme
montezdesousa Dec 21, 2022
f0f7bfb
move tests to core
montezdesousa Dec 21, 2022
fd5a058
Update README.md
montezdesousa Dec 21, 2022
416bcb7
Update README.md
montezdesousa Dec 21, 2022
2e75c19
move readme outside
montezdesousa Dec 21, 2022
79d7580
Merge branch 'feature/integration_tests' of github.com:OpenBB-finance…
montezdesousa Dec 21, 2022
25aa70e
Update README.md
montezdesousa Dec 21, 2022
c153967
Update README.md
montezdesousa Dec 21, 2022
ab3189b
Update README.md
montezdesousa Dec 21, 2022
b0c49d2
Update README.md
montezdesousa Dec 21, 2022
4cd5da8
Update README.md
montezdesousa Dec 21, 2022
81d1566
Update README.md
montezdesousa Dec 21, 2022
caba002
Update README.md
montezdesousa Dec 21, 2022
dad99a1
Update README.md
montezdesousa Dec 21, 2022
4886a63
Update README.md
montezdesousa Dec 21, 2022
299bf10
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 21, 2022
df19d78
parse subproc arg
montezdesousa Dec 21, 2022
b9fd30c
Update README.md
montezdesousa Dec 27, 2022
38fcd9d
Merge branch 'main' into feature/integration_tests
montezdesousa Dec 27, 2022
dc269e9
Merge branch 'main' into feature/integration_tests
jmaslek Jan 3, 2023
80dfd9a
Fix plot look when using eval and add query to choices (#3881)
montezdesousa Jan 6, 2023
fc58757
Lock ruff version so that new lints dont break our CI (#3905)
colin99d Jan 9, 2023
20e98d3
Delete glossary base command
Chavithra Jan 10, 2023
73bfb77
Merge branch 'feature/integration_tests' of github.com:OpenBB-finance…
montezdesousa Jan 10, 2023
a6cb733
move scripts
montezdesousa Jan 10, 2023
be7fd69
ruff
montezdesousa Jan 10, 2023
59b0b60
update pyproject.toml
montezdesousa Jan 10, 2023
9a3b6b4
update yfinance
montezdesousa Jan 10, 2023
7c2e2fe
fix futures and economy test, rewrite
montezdesousa Jan 11, 2023
9dfbd31
rewrite stocks test yfinance dependent
montezdesousa Jan 11, 2023
a7a9856
refactor sia to yfinance 0.2...
montezdesousa Jan 11, 2023
8d25393
fix last failing sia tests
montezdesousa Jan 11, 2023
da149ea
black
montezdesousa Jan 11, 2023
ffce14c
Merge branch 'develop' into feature/integration_tests
montezdesousa Jan 11, 2023
7d8a5c5
update reqs
montezdesousa Jan 11, 2023
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
271 changes: 271 additions & 0 deletions openbb_terminal/core/integration_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
# OpenBB Terminal : `Integration Testing`

This document is part of the `OpenBB Terminal` library documentation.

It aims to provide necessary information in order to:

- Build `integration tests`
- Run `integration tests`
- Identify errors noted from `integration tests`

## 1.1. Why have integration tests ?

The purpose of integration tests is to provide standard usage examples that can be programmatically run
to make sure that a specific functionality of the terminal and the process to utilize that functionality
is working properly.

## 2. How to build integration tests ?

Integration tests themselves are the same as manually running a certain series of steps. As a result,
writing tests is easy because the integration test script is just the total list of steps necessary to
use a command, command with specific argument, or series of commands.

When you contribute a new feature to the Terminal, it's important that integration tests are added for
this particular feature. It is a part of the Checklist for the PR to be approved.

All the `integration tests` should be insides the `scripts` folder. The naming convention for scripts
should be `test_<menu>_<command>.openbb` if you are testing a specific command or `test_<menu>.openbb`
if you are testing the entire menu. However, it is encouraged to create as specific of integration tests
as possible to identify errors more precisely. Additionally, all tests must end with the `exit` command.

These files can be given dynamic output with the following syntax `${key=default}`. Please note that
both key and default can only contain letters and numbers with NO special characters. Each dynamic
argument MUST contain a key and a default value.

## 3. How integration tests detect bugs ?

When an unhandled exception is raised during a test session, this is considered a bug. The exception is caught and we save its traceback and other details to debug afterwards.

### Script examples

Testing a specific command and it's arguments:

```zsh
script: test_alt_covid.openbb
- - - - - - - - - -
alternative
covid
country Australia
reset
slopes
country US
ov
country Russia
deaths
country United Kingdom
cases
country Canada
rates
exit
```

Testing an entire menu

```zsh
test_stocks_options.openbb
- - - - - - - - - -
stocks
options
screen
view
view high_IV
set high_IV
scr
q
unu
calc
load aapl
exp 0
pcr
info
chains
oi
vol
voi
hist 100
grhist 100
plot -x ltd -y iv
parity
binom
load spy
vsurf
exit
```

## 3. How to run integration tests ?

### Conda Terminal

After navigating to the location of the OpenBBTerminal repo, one can run integration tests in a
few different ways using the wildcard expression. Please include a `-t` with `terminal.py` to run
the tests.

- To see the available tests, use `--list` or `-l`:

```zsh
python terminal.py -t -l
```

- Run all integration tests:

```zsh
python terminal.py -t
```

- Run some integration tests, by number, name or path:

```zsh
python terminal.py -t -p 0 10 22
```

```zsh
python terminal.py -t -p stocks cryptocurrency
```

*This specific example runs all of the stocks integration tests. One can use this same format for different tests.*

```zsh
python terminal.py -t openbb_terminal/core/integration_tests/scripts/forex
```

- Run one integration test:

```zsh
python terminal.py -t -p alternative/test_alt_covid.openbb
```

*Note that the base path is `OpenBBTerminal/openbb_terminal/core/integration_tests/scripts`.*

- Skip some integration tests:

```zsh
python terminal.py -t -p alternative -s alternative/test_alt_covid.openbb
```

- Run integration tests with arguments by adding --key=value:

```zsh
python terminal.py -t --ticker=aapl
```

- To see the possible keys, use `--help` or `-h`:

```zsh
python terminal.py -t -h
```

- To save time, the tests are run in parallel by default. You can choose the number of subprocesses used with `--subproc`. The default number of subprocesses is the minimum between the number of scripts to run and the number of CPUs of your machine.

```zsh
python terminal.py -t forex --subproc 4
```

- To see terminal outputs being printed during the test session, use `--verbose` or `-v`:

```zsh
python terminal.py -t -v
```

- In verbose mode the tests are run sequentially, by default. This avoids mixing the outputs from several scripts in the console. If you still want to see the outputs during a parallel run, just specify the number of subprocesses you wish to launch with verbose flag, it will force multiprocessing.

```zsh
python terminal.py -t forex --subproc 7 -v
```

### Installer Terminal

Integration tests can also be used on installers, which is a packaged version of the conda terminal.
More information on how to build an installer can be found [here](/build/README.md).
To run the tests on installers you can use the same syntax as above, just substitute `python terminal.py` by the full path to OpenBBTerminal executable (not the shortcut!). See the examples below for MacOS.

- Run all integration tests:

```zsh
/Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal -t
```

- Run some integration tests:

```zsh
/Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal -t forex stocks
```

- Run one integration test:

```zsh
/Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal -t alternative/test_alt_covid.openbb
```

## 4. Test report

The console report has 3 sections: progress, failures and summary.

- Progress
1. Shows the tests collected and skipped in the current session
2. Informs if tests are running in parallel or sequentially
3. Displays the result of tests already finished

- Failures
1. Traceback
2. Exception type
3. Detail with exception message

- Summary
1. Displays tests failed with the last command called and how long they took to run

- Example

```zsh
(obb) % python terminal.py -t forex
============================ integration test session starts =============================
Collecting scripts from: /Users/username/OpenBBTerminal/openbb_terminal/core/integration_tests/scripts


* Collected 7 script(s)...
* Skipping 0 script(s)...
* Running 7 script(s) in 7 parallel subprocess(es)...

forex/test_forex_av.openbb [ 14%]
forex/test_forex_base.openbb [ 29%]
forex/test_forex_load.openbb [ 43%]
forex/test_forex_oanda.openbb [ 57%]
forex/test_forex_oanda_base.openbb [ 71%]
forex/test_forex_qa.openbb [ 86%]
forex/test_forex_ta.openbb [100%]

======================================== FAILURES ========================================
------------------------------- forex/test_forex_qa.openbb -------------------------------

Traceback:
File "/Users/username/OpenBBTerminal/openbb_terminal/core/integration_tests/integration_controller.py", line 299, in run_test
run_scripts(
File "/Users/username/OpenBBTerminal/openbb_terminal/core/integration_tests/integration_controller.py", line 272, in run_scripts
terminal(file_cmds, test_mode=True)
File "/Users/username/OpenBBTerminal/openbb_terminal/terminal_controller.py", line 905, in terminal
t_controller.queue = t_controller.switch(an_input)
File "/Users/username/OpenBBTerminal/openbb_terminal/decorators.py", line 64, in wrapper
value = func(*args, **kwargs)
File "/Users/username/OpenBBTerminal/openbb_terminal/parent_classes.py", line 363, in switch
getattr(
File "/Users/username/OpenBBTerminal/openbb_terminal/terminal_controller.py", line 401, in call_forex
self.queue = self.load_class(ForexController, self.queue)
File "/Users/username/OpenBBTerminal/openbb_terminal/parent_classes.py", line 219, in load_class
return class_ins(*args, **kwargs).menu()
File "/Users/username/OpenBBTerminal/openbb_terminal/parent_classes.py", line 934, in menu
self.queue = self.switch(an_input)
File "/Users/username/OpenBBTerminal/openbb_terminal/decorators.py", line 64, in wrapper
value = func(*args, **kwargs)
File "/Users/username/OpenBBTerminal/openbb_terminal/parent_classes.py", line 363, in switch
getattr(
File "/Users/username/OpenBBTerminal/openbb_terminal/decorators.py", line 64, in wrapper
value = func(*args, **kwargs)
File "/Users/username/OpenBBTerminal/openbb_terminal/forex/forex_controller.py", line 434, in call_qa
1 / 0
Exception type: ZeroDivisionError
Detail: division by zero
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

================================ integration test summary ================================
FAILED forex/test_forex_qa.openbb -> command: qa
============================== 1 failed, 6 passed in 8.88s ===============================
```
Loading