Skip to content

Commit

Permalink
Code Qual fixes, changed out valuless test
Browse files Browse the repository at this point in the history
  • Loading branch information
JL-Brothers committed Aug 27, 2024
1 parent bdb3ba2 commit 5623ec9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion openc3/python/test/models/test_interface_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# if purchased from OpenC3, Inc.

import unittest
from unittest.mock import *
from unittest.mock import patch, MagicMock
from test.test_helper import *
from openc3.models.interface_model import InterfaceModel
from openc3.models.router_model import RouterModel
Expand Down
64 changes: 44 additions & 20 deletions openc3/python/test/models/test_target_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,59 @@
import time
from typing import Optional
import unittest

from test.test_helper import *

from openc3.models.model import Model

from unittest.mock import *
from unittest.mock import patch, MagicMock
from openc3.models.target_model import TargetModel
from openc3.conversions.generic_conversion import GenericConversion

from pprint import pprint

class TestTargetModel(unittest.TestCase):
def setUp(self):
mock_redis(self)
#model = ScopeModel.new(name: "DEFAULT")
#model.create

def test_returns_all_model_names(self):
model = TargetModel(folder_name= "TEST", name= "TEST", scope= "DEFAULT")
pprint(dir(model))
model.create
model = TargetModel(folder_name= "SPEC", name= "SPEC", scope= "DEFAULT")
model.create
model = TargetModel(folder_name= "OTHER", name= "OTHER", scope= "OTHER")
model.create
names = TargetModel.names(scope= "DEFAULT")
pprint(names)
# contain_exactly doesn't care about ordering and neither do we
#expect(names).to contain_exactly("TEST", "SPEC")
#names = TargetModel.names(scope= "OTHER")
#expect(names).to contain_exactly("OTHER")
@patch('openc3.models.model.Model.names')
def test_names_with_default_scope(self, mock_super_names):
# Arrange
expected_names = ['TARGET1', 'TARGET2', 'TARGET3']
mock_super_names.return_value = expected_names
default_scope = 'DEFAULT'
# Act
result = TargetModel.names(default_scope)
# Assert
self.assertEqual(result, expected_names)
mock_super_names.assert_called_once_with(f'{default_scope}__openc3_targets')

@patch('openc3.models.model.Model.names')
def test_names_with_custom_scope(self, mock_super_names):
# Arrange
expected_names = ['CUSTOM_TARGET1', 'CUSTOM_TARGET2']
mock_super_names.return_value = expected_names
custom_scope = 'CUSTOM_SCOPE'
# Act
result = TargetModel.names(custom_scope)
# Assert
self.assertEqual(result, expected_names)
mock_super_names.assert_called_once_with(f'{custom_scope}__openc3_targets')

@patch('openc3.models.model.Model.names')
def test_names_with_empty_result(self, mock_super_names):
# Arrange
mock_super_names.return_value = []
scope = 'EMPTY_SCOPE'
# Act
result = TargetModel.names(scope)
# Assert
self.assertEqual(result, [])
mock_super_names.assert_called_once_with(f'{scope}__openc3_targets')

@patch('openc3.models.model.Model.names')
def test_names_with_none_scope(self, mock_super_names):
# Arrange
expected_names = ['TARGET_X', 'TARGET_Y']
mock_super_names.return_value = expected_names
# Act & Assert
with self.assertRaises(TypeError):
TargetModel.names(None)
mock_super_names.assert_not_called()

0 comments on commit 5623ec9

Please sign in to comment.