Coverage for tests/conftest.py: 93%

28 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-16 22:05 +0000

1import os 

2 

3import pytest 

4 

5from bbconf.bbagent import BedBaseAgent 

6 

7from .utils import BED_TEST_ID 

8 

9DB_CMD = """ 

10docker run --rm -it --name bedbase-test \ 

11 -e POSTGRES_USER=postgres \ 

12 -e POSTGRES_PASSWORD=docker\ 

13 -e POSTGRES_DB=bedbase \ 

14 -p 5432:5432 postgres 

15""" 

16 

17TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) 

18 

19CONFIG_PATH = os.path.join( 

20 TESTS_DIR, 

21 "config_test.yaml", 

22) 

23DATA_PATH = os.path.join( 

24 TESTS_DIR, 

25 "data", 

26) 

27 

28# try: 

29# BedBaseAgent(config=CONFIG_PATH) 

30# SERVICE_UNAVAILABLE = False 

31# except Exception as _: 

32# SERVICE_UNAVAILABLE = True 

33SERVICE_UNAVAILABLE = False 

34 

35 

36if not SERVICE_UNAVAILABLE: 

37 agent = BedBaseAgent(config=CONFIG_PATH) 

38 

39 

40def get_bbagent(): 

41 return agent 

42 

43 

44@pytest.fixture(scope="function") 

45def bbagent_obj(): 

46 yield agent 

47 

48 

49@pytest.fixture() 

50def example_bedset_plot(): 

51 return { 

52 "name": "chrombins", 

53 "description": "Regions distribution over chromosomes", 

54 "title": "Regions distribution over chromosomes", 

55 "path": "data/plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.pdf", 

56 "path_thumbnail": "data/plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.png", 

57 "bedset_id": BED_TEST_ID, 

58 } 

59 

60 

61@pytest.fixture() 

62def example_dict(): 

63 plots = { 

64 "chrombins": { 

65 "name": "Regions distribution over chromosomes", 

66 "path": "plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.pdf", 

67 "path_thumbnail": "plots/bbad85f21962bb8d972444f7f9a3a932_chrombins.png", 

68 } 

69 } 

70 files = { 

71 "bedfile": { 

72 "name": "Bed file", 

73 "path": os.path.join( 

74 DATA_PATH, "files/bbad85f21962bb8d972444f7f9a3a932.bed.gz" 

75 ), 

76 "description": "Bed file with regions", 

77 } 

78 } 

79 classification = { 

80 "data_format": "encode_narrowpeak", 

81 "bed_compliance": "bed6+4", 

82 "genome_alias": "hg38", 

83 "genome_digest": "2230c535660fb4774114bfa966a62f823fdb6d21acf138d4", 

84 "name": "bbad85f21962bb8d972444f7f9a3a932", 

85 } 

86 

87 return dict( 

88 identifier="bbad85f21962bb8d972444f7f9a3a932", 

89 stats={ 

90 "number_of_regions": 1, 

91 "median_tss_dist": 2, 

92 "mean_region_width": 3, 

93 "exon_frequency": 4, 

94 "exon_percentage": 5, 

95 "intron_frequency": 6, 

96 "intron_percentage": 7, 

97 "intergenic_percentage": 8, 

98 "intergenic_frequency": 9, 

99 "promotercore_frequency": 10, 

100 "promotercore_percentage": 11, 

101 "fiveutr_frequency": 12, 

102 "fiveutr_percentage": 13, 

103 "threeutr_frequency": 14, 

104 "threeutr_percentage": 15, 

105 "promoterprox_frequency": 16, 

106 "promoterprox_percentage": 17, 

107 }, 

108 metadata={ 

109 "sample_name": "sample_name_1", 

110 "species_name": "species_name", 

111 "species_id": "123", 

112 }, 

113 plots=plots, 

114 files=files, 

115 classification=classification, 

116 upload_qdrant=False, 

117 upload_s3=True, 

118 local_path=DATA_PATH, 

119 overwrite=False, 

120 nofail=False, 

121 ) 

122 

123 

124@pytest.fixture 

125def load_test_data(): 

126 get_bbagent().config.db_engine()