A Python library for working with time series data. It comes with common financial functions built-in.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Gourav Kumar a4ecd38b97 All transform tests are now passing 9 months ago
..
data Series tests pass data type as string 2 years ago
README.md renamed file 2 years ago
__init__.py Setup package and tested with tox 2 years ago
conftest.py updated some tests, added test for shrink, not working yet 1 year ago
test_core.py tests for sortino and missing frequency 2 years ago
test_pyfacts.py All transform tests are now passing 9 months ago
test_stats.py sortino tests are now passing 2 years ago
test_utils.py improved Readme 2 years ago

README.md

Testing Guidelines

PyFacts uses Pytest for unit testing.

All high level functions are expected to have tests written for them. Each file in the pyfacts module has a dedicated test file. All tests related to that file go within the respective test files.

Since this module needs test data for testing, a Pytest fixture has been defined to generate test data. Use this fixture to generate test data. The fixture uses the random module to generate random test data. A seed has been hardcoded for the random data generator to ensure it generates the same data all the time (if it didn't, tests for specific values would never pass). WARNING! Do not change the seed for the random data generator. This will cause most tests to fail.

To use the fixture, just pass create_test_data as an argument to the test function and then use it within the function. Pytest will automatically locate the relevant function (it need not be imported into the test file).

Writing tests

Tests are organised as follows:

  • Each broad function/method has a Test Class
  • All variations should be tested within this class using one or more functions

All test files should be named test_<module_file_name>.py. For instance, test file for core.py is named test_core.py

All class names should begin with the word Test. All function names should begin with the word test_.

It needs to be ensured that all test functions are independent of each other.

Running tests

Skip this part if you already know how to run pytest.

Open the terminal. Make sure you are in the root pyfacts folder. Then run the following command: pytest tests

This will run the entire test suite. This can take some time depending on the number of tests and speed of your computer. Hence you might want to run only a few tests.

To run tests within a particular file, say test_core.py, type the following command: pytest tests/test_core.py

If you want to run only a particular class within a file, for instance TestSetitem within the test_core.py file, run them as follows: pytest tests/test_core.py::TestSetitem

This will run only the specified class, making sure your tests don't take too long.

If you're using VS Code, you can make this whole process easier by configuring pytest within VS Code. It will identify all tests and allow you to run them individually from the testing pane on the left.

Before you push your code

Before you push your code or raise a PR, ensure that all tests are passing. PRs where any of the tests are failing will not be merged. Any modifications to the code which require a modification to existing tests should be accompanied with a note in the PR as to the reasons existing tests had to be modified.