Skip to content

Commit

Permalink
fixed: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Teingi committed Dec 11, 2024
1 parent 4428163 commit 9340994
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions test/common/test_config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@


class TestConfigHelper(unittest.TestCase):
@mock.patch('common.config_helper.YamlUtils.write_yaml_data')
@mock.patch('common.config_helper.DirectoryUtil.mkdir')
@mock.patch('common.config_helper.os.path.expanduser')
@mock.patch('common.config_helper.TimeUtils.timestamp_to_filename_time')
@mock.patch('src.common.config_helper.YamlUtils.write_yaml_data')
@mock.patch('src.common.config_helper.DirectoryUtil.mkdir')
@mock.patch('src.common.config_helper.os.path.expanduser')
@mock.patch('src.common.config_helper.TimeUtils.timestamp_to_filename_time')
def test_save_old_configuration(self, mock_timestamp_to_filename_time, mock_expanduser, mock_mkdir, mock_write_yaml_data):
# 模拟时间戳生成函数,返回一个特定的值
mock_timestamp_to_filename_time.return_value = '20240806_123456'
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_input_with_default(self, mock_input):
self.assertEqual(result, 'custom_user')

# 测试带有默认值的密码输入方法
@mock.patch('common.config_helper.pwinput.pwinput')
@mock.patch('src.common.config_helper.pwinput.pwinput')
def test_input_password_with_default(self, mock_pwinput):
# 创建一个模拟的上下文对象
context = mock.MagicMock()
Expand All @@ -120,7 +120,7 @@ def test_input_password_with_default(self, mock_pwinput):
self.assertEqual(result, "custom_password")

# 测试带有默认选项的选择输入方法
@mock.patch('common.config_helper.input')
@mock.patch('src.common.config_helper.input')
def test_input_choice_default(self, mock_input):
# 创建一个模拟的上下文对象
context = mock.MagicMock()
Expand Down
10 changes: 5 additions & 5 deletions test/common/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,29 @@ def test_wildcard_max_version(self):
result = filter_by_version(scene, cluster, self.stdio)
self.assertEqual(result, 0)

@patch('common.scene.get_observer_version')
@patch('src.common.scene.get_observer_version')
def test_get_observer_version(self, mock_get_observer_version):
mock_get_observer_version.return_value = "1.0.0"
result = get_version_by_type(self.context, "observer")
self.assertEqual(result, "1.0.0")
mock_get_observer_version.assert_called_once_with(self.context)

@patch('common.scene.get_observer_version')
@patch('src.common.scene.get_observer_version')
def test_get_other_version(self, mock_get_observer_version):
mock_get_observer_version.return_value = "2.0.0"
result = get_version_by_type(self.context, "other")
self.assertEqual(result, "2.0.0")
mock_get_observer_version.assert_called_once_with(self.context)

@patch('common.scene.get_observer_version')
@patch('src.common.scene.get_observer_version')
def test_get_observer_version_fail(self, mock_get_observer_version):
mock_get_observer_version.side_effect = Exception("Observer error")
with self.assertRaises(Exception) as context:
get_version_by_type(self.context, "observer")
self.assertIn("can't get observer version", str(context.exception))
self.context.stdio.warn.assert_called_once()

@patch('common.scene.get_obproxy_version')
@patch('src.common.scene.get_obproxy_version')
def test_get_obproxy_version(self, mock_get_obproxy_version):
mock_get_obproxy_version.return_value = "3.0.0"
result = get_version_by_type(self.context, "obproxy")
Expand All @@ -134,7 +134,7 @@ def test_unsupported_type(self):
get_version_by_type(self.context, "unsupported")
self.assertIn("No support to get the version", str(context.exception))

@patch('common.scene.get_observer_version')
@patch('src.common.scene.get_observer_version')
def test_general_exception_handling(self, mock_get_observer_version):
mock_get_observer_version.side_effect = Exception("Unexpected error")
with self.assertRaises(Exception) as context:
Expand Down

0 comments on commit 9340994

Please sign in to comment.