Coverage for mpcforces_extractor\database\test_database.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-17 23:11 +0200

1import pytest 

2from mpcforces_extractor.database.database import MPCDatabase 

3from mpcforces_extractor.datastructure.rigids import MPC, MPC_CONFIG 

4from mpcforces_extractor.datastructure.entities import Node, Element 

5 

6from fastapi import HTTPException 

7 

8 

9# Define the initial MPC instances 

10node1 = Node(1, [0, 0, 0]) 

11node2 = Node(2, [1, 2, 3]) 

12node3 = Node(3, [4, 5, 6]) 

13node4 = Node(4, [0, 0, 0]) 

14node5 = Node(5, [1, 2, 3]) 

15node6 = Node(6, [4, 5, 6]) 

16 

17MPC.reset() 

18MPC( 

19 element_id=1, 

20 mpc_config=MPC_CONFIG.RBE2, 

21 master_node=node1, 

22 nodes=[node2, node3], 

23 dofs="", 

24) 

25MPC( 

26 element_id=2, 

27 mpc_config=MPC_CONFIG.RBE3, 

28 master_node=node4, 

29 nodes=[node5, node6], 

30 dofs="", 

31) 

32 

33Element(1, 1, [node2, node3]) 

34Element(2, 2, [node6, node5]) 

35 

36 

37db = MPCDatabase() 

38 

39 

40@pytest.mark.asyncio 

41async def test_initialize_database(): 

42 assert len(await db.get_mpcs()) == 2 # Check initial population 

43 

44 

45@pytest.mark.asyncio 

46async def test_get_mpc(): 

47 mpc = await db.get_mpc(1) # Await the async function 

48 assert mpc.id == 1 

49 assert mpc.config == "RBE2" 

50 

51 

52@pytest.mark.asyncio 

53async def test_remove_mpc(): 

54 await db.remove_mpc(1) # Await the async function 

55 with pytest.raises(HTTPException): 

56 await db.get_mpc(1) # Await the async function