Skip to content

Commit

Permalink
[Test] Add test cases for RecceConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <[email protected]>
  • Loading branch information
kentwelcome committed Dec 16, 2024
1 parent 996aec1 commit 39c44b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/data/config/recce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Preset Checks
# Please see https://datarecce.io/docs/features/preset-checks/
checks:
- name: Row count diff
description: Check the row count diff for all table models.
type: row_count_diff
params:
select: state:modified,config.materialized:table
- name: Schema diff
description: Check the schema diff for all nodes.
type: schema_diff
37 changes: 37 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os.path
from unittest import TestCase
from unittest.mock import patch

from recce.config import RecceConfig
from recce.util import SingletonMeta

test_root_path = os.path.dirname(os.path.abspath(__file__))


class RecceConfigTestCase(TestCase):
def setUp(self):
self.recce_config_path = os.path.join(test_root_path, 'data', 'config', 'recce.yml')
pass

def tearDown(self):
# Reset the SingletonMeta instances due to RecceConfig is a singleton
SingletonMeta._instances = {}

def test_load_recce_config(self):
config = RecceConfig(self.recce_config_path)

# Test data contains 2 checks
preset_checks = config.config.get('checks')
self.assertIsNotNone(preset_checks)
self.assertIsInstance(preset_checks, list)
self.assertEqual(len(preset_checks), 2)

@patch('recce.config.RecceConfig.save')
def test_recce_config_not_found(self, mock_save):
default_config = RecceConfig('NOT_EXISTING_FILE')
assert mock_save.called is True
# Default config should be generated
preset_checks = default_config.config.get('checks')
self.assertIsNotNone(default_config.config)
self.assertIsInstance(preset_checks, list)
self.assertEqual(len(preset_checks), 2)

0 comments on commit 39c44b7

Please sign in to comment.