Coverage for mpcforces_extractor\reader\test_mpcforces_reader.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-06 21:34 +0100

1import unittest 

2from unittest.mock import patch 

3 

4from mpcforces_extractor.reader.mpcforces_reader import MPCForcesReader 

5from mpcforces_extractor.datastructure.subcases import Subcase 

6 

7 

8@patch( 

9 "mpcforces_extractor.reader.mpcforces_reader.MPCForcesReader._MPCForcesReader__read_lines" 

10) 

11class TestMPCForcesReader(unittest.TestCase): 

12 def test_forces(self, mock_read_lines): 

13 mpc_file_path = "dummypath" 

14 mock_read_lines.return_value = [ 

15 "$SUBCASE 1\n", 

16 "$TIME 0.0\n", 

17 "GRID # X-FORCE Y-FORCE Z-FORCE X-MOMENT Y-MOMENT Z-MOMENT\n", 

18 "--------+-----------------------------------------------------------------------------\n", 

19 " 1 -1.00000E-00 1.00000E-00 1.00000E-00 1.00000E-00\n", 

20 " 2 -1.00000E-00 1.00000E-00 1.00000E-00 1.00000E-00\n", 

21 "", 

22 ] 

23 

24 mpc_reader = MPCForcesReader(mpc_file_path) 

25 mpc_reader.file_content = mock_read_lines.return_value 

26 mpc_reader.build_subcases() 

27 

28 self.assertEqual(len(Subcase.subcases), 1) 

29 subacase = Subcase.subcases[0] 

30 self.assertEqual( 

31 subacase.node_id2forces[1], 

32 [-1.0, 1.0, 1.0, 1.0, 0.0, 0.0], 

33 ) 

34 self.assertEqual( 

35 Subcase.get_subcase_by_id(1).node_id2forces[2], 

36 [-1.0, 1.0, 1.0, 0.0, 1.0, 0.0], 

37 )