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

Sorr task918 add unit test for split universe #996

Merged
merged 20 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2e89757
Added test for _split_universe()
smitpatel49 May 21, 2024
6476255
update1
smitpatel49 May 21, 2024
2abb4e9
requirements
smitpatel49 May 21, 2024
d8fabff
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 May 21, 2024
49aa798
Added the requested test
smitpatel49 May 24, 2024
e4b6acc
Updated according to the requested changes
smitpatel49 May 29, 2024
04f351a
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 May 30, 2024
886f3f6
Corrected a minor mistake
smitpatel49 May 31, 2024
1a3d24e
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 May 31, 2024
4a0c9ab
Merge branch 'SorrTask918_Add_unit_test_for_split_universe' of https:…
smitpatel49 May 31, 2024
796234d
Updated assertRaises explanation
smitpatel49 May 31, 2024
efb5bf9
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 May 31, 2024
501c886
Updated according to the review
smitpatel49 May 31, 2024
fd319b2
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 Jun 3, 2024
e61cd37
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
smitpatel49 Jun 3, 2024
350496f
Added a test and made changes according to the review
smitpatel49 Jun 3, 2024
523517f
Merge branch 'SorrTask918_Add_unit_test_for_split_universe' of https:…
smitpatel49 Jun 3, 2024
d7c0961
Added the missing code
smitpatel49 Jun 5, 2024
b681c5f
Fixed the typo and removed one test
smitpatel49 Jun 6, 2024
401c582
Merge branch 'master' into SorrTask918_Add_unit_test_for_split_universe
samarth9008 Jun 6, 2024
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
90 changes: 87 additions & 3 deletions im_v2/common/data/extract/test/test_extract_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import os
import unittest.mock as umock
from datetime import datetime, timedelta
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

import pandas as pd
import pytest

import helpers.hdatetime as hdateti
import helpers.henv as henv
import helpers.hmoto as hmoto
import helpers.hpandas as hpandas
Expand Down Expand Up @@ -820,6 +819,88 @@ def test_download_and_resample_bid_ask_data(self) -> None:
self.check_resampler()


class TestSplitUniverse(hunitest.TestCase):
smitpatel49 marked this conversation as resolved.
Show resolved Hide resolved
def helper(self, group_size: int, universe_part: int) -> List:
"""
Run the function and get a string representation of its output.
"""
universe = [
"ALICE_USDT",
"GALA_USDT",
"FLOW_USDT",
"HBAR_USDT",
"INJ_USDT",
"NEAR_USDT",
]
actual_output = imvcdeexut._split_universe(
universe, group_size, universe_part
)
output_str = str(actual_output)
return output_str

def test1(self) -> None:
"""
Check that universe is split correctly.
"""
group_size = 0
universe_part = 0
actual_str = self.helper(group_size, universe_part)
expected_str = r"""
[]
"""
self.assert_equal(actual_str, expected_str, fuzzy_match=True)
smitpatel49 marked this conversation as resolved.
Show resolved Hide resolved

def test2(self) -> None:
"""
Check that universe is split correctly.
"""
group_size = 6
universe_part = 1
actual_str = self.helper(group_size, universe_part)
expected_str = r"""
['ALICE_USDT', 'GALA_USDT', 'FLOW_USDT', 'HBAR_USDT', 'INJ_USDT', 'NEAR_USDT']
"""
self.assert_equal(actual_str, expected_str, fuzzy_match=True)

def test3(self) -> None:
"""
Check that universe is split correctly.
"""
group_size = 6
universe_part = 2
actual_str = self.helper(group_size, universe_part)
expected_str = r"""
[]
"""
self.assert_equal(actual_str, expected_str, fuzzy_match=True)

def test4(self) -> None:
"""
Check that universe is split correctly.
"""
group_size = 4
universe_part = 2
actual_str = self.helper(group_size, universe_part)
expected_str = r"""
['INJ_USDT', 'NEAR_USDT']
"""
self.assert_equal(actual_str, expected_str, fuzzy_match=True)

def test5(self) -> None:
"""
Check the error is raised if universe does not have input part.
"""
group_size = 6
universe_part = 7
with self.assertRaises(RuntimeError) as cm:
self.helper(group_size, universe_part)
actual_str = str(cm.exception)
expected_str = r"""
Universe does not have 7 parts of 6 pairs. It has 6 symbols.
"""
self.assert_equal(actual_str, expected_str, fuzzy_match=True)


@pytest.mark.requires_ck_infra
@pytest.mark.requires_aws
@pytest.mark.skipif(
Expand Down Expand Up @@ -1766,7 +1847,9 @@ def test_download_websocket_ohlcv_futures1(
) -> None:
"""
Test the correct download of OHLCV data with consideration for
incomplete bars. Invariant #1.
incomplete bars.

Invariant #1.
"""
# Data received from exchange in second iteration.
next_data = {}
Expand Down Expand Up @@ -1815,6 +1898,7 @@ def test_download_websocket_ohlcv_futures3(
) -> None:
"""
Test the correct download of OHLCV data with backfilling.

Invariant #2.
"""
# Data received from exchange in second iteration.
Expand Down
Loading