Coverage for tests/test_universes.py: 31%

36 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-17 04:01 +0000

1import pytest 

2 

3from bbconf.exceptions import BEDFileNotFoundError 

4 

5from .conftest import SERVICE_UNAVAILABLE 

6from .utils import BED_TEST_ID, ContextManagerDBTesting 

7 

8 

9@pytest.mark.skipif(SERVICE_UNAVAILABLE, reason="Database is not available") 

10class TestUniverses: 

11 

12 def test_add(self, bbagent_obj): 

13 with ContextManagerDBTesting(config=bbagent_obj.config, add_data=True): 

14 bbagent_obj.bed.add_universe( 

15 BED_TEST_ID, bedset_id=None, construct_method="hp31" 

16 ) 

17 

18 assert bbagent_obj.bed.exists(BED_TEST_ID) 

19 assert bbagent_obj.bed.exists_universe(BED_TEST_ID) 

20 universe_meta = bbagent_obj.bed.get(BED_TEST_ID) 

21 assert universe_meta is not None 

22 assert universe_meta.is_universe is True 

23 

24 def test_delete_universe(self, bbagent_obj): 

25 with ContextManagerDBTesting(config=bbagent_obj.config, add_data=True): 

26 bbagent_obj.bed.add_universe( 

27 BED_TEST_ID, bedset_id=None, construct_method="hp31" 

28 ) 

29 

30 assert bbagent_obj.bed.exists_universe(BED_TEST_ID) 

31 

32 bbagent_obj.bed.delete_universe(BED_TEST_ID) 

33 

34 assert not bbagent_obj.bed.exists_universe(BED_TEST_ID) 

35 

36 def test_add_universe_error(self, bbagent_obj): 

37 with ContextManagerDBTesting(config=bbagent_obj.config, add_data=True): 

38 with pytest.raises(BEDFileNotFoundError): 

39 bbagent_obj.bed.add_universe( 

40 "not_f", bedset_id=None, construct_method="hp31" 

41 ) 

42 

43 def test_add_get_tokenized(self, bbagent_obj, mocker): 

44 with ContextManagerDBTesting(config=bbagent_obj.config, add_data=True): 

45 bbagent_obj.bed.add_universe( 

46 BED_TEST_ID, bedset_id=None, construct_method="hp31" 

47 ) 

48 

49 assert bbagent_obj.bed.exists_universe(BED_TEST_ID) 

50 

51 saved_path = "test/1/1" 

52 

53 zarr_mock = mocker.patch( 

54 "bbconf.modules.bedfiles.BedAgentBedFile._add_zarr_s3", 

55 return_value=saved_path, 

56 ) 

57 

58 bbagent_obj.bed.add_tokenized( 

59 bed_id=BED_TEST_ID, universe_id=BED_TEST_ID, token_vector=[1, 2, 3] 

60 ) 

61 

62 zarr_path = bbagent_obj.bed._get_tokenized_path( 

63 BED_TEST_ID, universe_id=BED_TEST_ID 

64 ) 

65 

66 assert zarr_mock.called 

67 assert f"s3://bedbase/{saved_path}" == zarr_path 

68 

69 def test_get_tokenized(self, bbagent_obj, mocked_phc): 

70 # how to test it? 

71 ...