Skip to content

Commit

Permalink
* open unittests for api-related ops
Browse files Browse the repository at this point in the history
  • Loading branch information
HYLcool committed Jan 21, 2025
1 parent 26d0f84 commit 6874191
Show file tree
Hide file tree
Showing 21 changed files with 21 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run unittest standalone
working-directory: dj-${{ github.run_id }}/.github/workflows/docker
run: |
docker compose exec ray-head python tests/run.py --tag standalone
docker compose exec -e OPENAI_BASE_URL=${{ secrets.OPENAI_BASE_URL }} -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} ray-head python tests/run.py --tag standalone
- name: Run unittest ray
working-directory: dj-${{ github.run_id }}/.github/workflows/docker
Expand Down
3 changes: 1 addition & 2 deletions tests/ops/aggregator/test_entity_attribute_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import EntityAttributeAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, BatchMetaKeys, MetaKeys


@SKIPPED_TESTS.register_module()
class EntityAttributeAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=BatchMetaKeys.entity_attribute):
Expand Down
4 changes: 1 addition & 3 deletions tests/ops/aggregator/test_meta_tags_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import MetaTagsAggregator
from data_juicer.utils.constant import Fields, MetaKeys
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


@SKIPPED_TESTS.register_module()
class MetaTagsAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import MostRelavantEntitiesAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase

from data_juicer.utils.constant import Fields, BatchMetaKeys, MetaKeys


@SKIPPED_TESTS.register_module()
class MostRelavantEntitiesAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=BatchMetaKeys.most_relavant_entities):
Expand Down
4 changes: 1 addition & 3 deletions tests/ops/aggregator/test_nested_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import NestedAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase

from data_juicer.utils.constant import Fields, MetaKeys


@SKIPPED_TESTS.register_module()
class NestedAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=MetaKeys.event_description):
Expand Down
28 changes: 1 addition & 27 deletions tests/ops/mapper/test_calibrate_qa_mapper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import os
import unittest
from unittest.mock import Mock, patch

import httpx
from loguru import logger

from data_juicer.ops.mapper.calibrate_qa_mapper import CalibrateQAMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateQAMapperTest(DataJuicerTestCaseBase):

def _run_op(self, op):
Expand Down Expand Up @@ -81,23 +73,5 @@ def test_args(self):
response_path='choices.0.message.content')
self._run_op(op)

@patch('httpx.Client.send')
def test_retry(self, mock_send):
mock_response = Mock()
mock_response.status_code = 408
mock_response.headers = {}
mock_request = Mock()
mock_response.raise_for_status.side_effect = httpx.HTTPStatusError(
'408 Client Error: Request Timeout',
request=mock_request,
response=mock_response)
mock_send.return_value = mock_response

with self.assertLogs(level='DEBUG') as cm:
op = CalibrateQAMapper(api_model='test',
model_params={'max_retries': 3})
op.process({'text': '', 'query': '', 'response': ''})
self.assertIn('3 retries left', '\n'.join(cm.output))

if __name__ == '__main__':
unittest.main()
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_calibrate_query_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
from loguru import logger

from data_juicer.ops.mapper.calibrate_query_mapper import CalibrateQueryMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateQueryMapperTest(DataJuicerTestCaseBase):

def _run_op(self, api_model, response_path=None):
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_calibrate_response_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

from data_juicer.ops.mapper.calibrate_response_mapper import \
CalibrateResponseMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateResponseMapperTest(DataJuicerTestCaseBase):

def _run_op(self, api_model, response_path=None):
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_dialog_intent_detection_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_intent_detection_mapper import DialogIntentDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogIntentDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_dialog_sentiment_detection_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_sentiment_detection_mapper import DialogSentimentDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogSentimentDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_dialog_sentiment_intensity_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_sentiment_intensity_mapper import DialogSentimentIntensityMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogSentimentIntensityMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_dialog_topic_detection_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_topic_detection_mapper import DialogTopicDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogTopicDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_entity_attribute_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_entity_attribute_mapper import ExtractEntityAttributeMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractEntityAttributeMapperTest(DataJuicerTestCaseBase):


Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_entity_relation_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_entity_relation_mapper import ExtractEntityRelationMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractEntityRelationMapperTest(DataJuicerTestCaseBase):


Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_event_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_event_mapper import ExtractEventMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractEventMapperTest(DataJuicerTestCaseBase):


Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_keyword_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_keyword_mapper import ExtractKeywordMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractKeywordMapperTest(DataJuicerTestCaseBase):


Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_nickname_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_nickname_mapper import ExtractNicknameMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractNicknameMapperTest(DataJuicerTestCaseBase):


Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_extract_support_text_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.extract_support_text_mapper import ExtractSupportTextMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class ExtractSupportTextMapperTest(DataJuicerTestCaseBase):


Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_pair_preference_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
from loguru import logger

from data_juicer.ops.mapper.pair_preference_mapper import PairPreferenceMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class PairPreferenceMapperTest(DataJuicerTestCaseBase):

def _run_op(self, op, samples):
Expand Down
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_relation_identity_mapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import unittest
import json

from loguru import logger

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.relation_identity_mapper import RelationIdentityMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class RelationIdentityMapperTest(DataJuicerTestCaseBase):

# before runing this test, set below environment variables:
Expand Down
3 changes: 1 addition & 2 deletions tests/ops/mapper/test_text_chunk_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.text_chunk_mapper import TextChunkMapper
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


@SKIPPED_TESTS.register_module()
class TextChunkMapperTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, target):
Expand Down

0 comments on commit 6874191

Please sign in to comment.