Skip to content

Commit

Permalink
tests for value parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zeynepgultugaydemir committed Nov 28, 2024
1 parent c7d9f40 commit c2a9ce3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qf_lib/data_providers/bloomberg/reference_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _parse_value(field_data_array, field_name):
value = field_element.getValueAsBool()
elif element_data_type in (DataType.DATETIME, DataType.DATE):
value = to_datetime(field_element.getValueAsDatetime())
elif element_data_type in DataType.TIME:
elif element_data_type is DataType.TIME:
value = field_element.getValueAsDatetime()
else:
value = field_element.getValueAsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2016-present CERN – European Organization for Nuclear Research
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
from unittest import TestCase

from data_providers.bloomberg import BloombergDataProvider
from qf_lib.common.tickers.tickers import BloombergTicker
from tests.integration_tests.data_providers.futures.test_general_price_provider import bbg_provider
from tests.unit_tests.config.test_settings import get_test_settings


class TestBloombergValueParser(TestCase):

def setUp(self) -> None:
self.ticker = BloombergTicker("EUITEMUM Index")

try:
settings = get_test_settings()
self.bbg_provider = BloombergDataProvider(settings)
bbg_provider.connect()

except Exception as e:
raise self.skipTest(e)

def test_get_string_values(self):
field = "OBSERVATION_PERIOD"
result = self.bbg_provider.get_current_values(self.ticker, field)
self.assertIsInstance(result, str)

def test_get_float_values(self):
field = "PX_Last"
result = self.bbg_provider.get_current_values(self.ticker, field)
self.assertIsInstance(result, float)

def test_get_date_values(self):
field = "ECO_RELEASE_DT"
result = self.bbg_provider.get_current_values(self.ticker, field)
self.assertIsInstance(result, datetime.datetime)

def test_get_time_values(self):
field = "ECO_RELEASE_TIME"
result = self.bbg_provider.get_current_values(self.ticker, field)
self.assertIsInstance(result, datetime.time)

def test_get_none_values(self):
field = "BN_SURVEY_MEDIAN"
result = self.bbg_provider.get_current_values(self.ticker, field)
self.assertIsNone(result)

0 comments on commit c2a9ce3

Please sign in to comment.