def test_single_sample( self, tmpdir, path_proj_conf_file, which_sample_index): """ Single Sample is perfectly valid for Project and sheet. """ # Pull out the values for the current sample. values = DATA[which_sample_index] # Write the annotations. anns_path = os.path.join(tmpdir.strpath, NAME_ANNOTATIONS_FILE) with open(anns_path, 'w') as anns_file: anns_file.write("{}\n".format(",".join(COLUMNS))) anns_file.write("{}\n".format(",".join([str(v) for v in values]))) # Build the sheet. p = Project(path_proj_conf_file) sheet = p.build_sheet() # It should be a single-row DataFrame. assert isinstance(sheet, pd.DataFrame) assert 1 == len(sheet) assert 1 == p.num_samples # There will be additional values added from the Project, # but the core data values will have remained the same. sample = list(p.samples)[0] for attr, exp_val in zip(COLUMNS, values): obs_val = getattr(sample, attr) try: assert exp_val == obs_val except AssertionError as e: try: assert exp_val == int(obs_val) except AssertionError: raise e
def test_multiple_samples(self, protocols, path_anns_file, path_proj_conf_file): """ Project also processes multiple Sample fine. """ p = Project(path_proj_conf_file) # Total sample count is constant. assert len(SAMPLE_NAMES) == sum(1 for _ in p.samples) # But the sheet permits filtering to specific protocol(s). exp_num_samples = len(SAMPLE_NAMES) if not protocols else \ sum(sum(1 for p2 in PROTOCOLS if p2 == p1) for p1 in protocols) sheet = p.build_sheet(*protocols) assert exp_num_samples == len(sheet) if protocols: def as_expected(sd): return sd.protocol in set(protocols) else: def as_expected(sd): return sd.protocol not in set(protocols) for _, sample_data in sheet.iterrows(): assert as_expected(sample_data)
def test_single_sample(self, tmpdir, path_proj_conf_file, which_sample_index): """ Single Sample is perfectly valid for Project and sheet. """ # Pull out the values for the current sample. values = DATA[which_sample_index] # Write the annotations. anns_path = os.path.join(tmpdir.strpath, NAME_ANNOTATIONS_FILE) with open(anns_path, 'w') as anns_file: anns_file.write("{}\n".format(",".join(COLUMNS))) anns_file.write("{}\n".format(",".join([str(v) for v in values]))) # Build the sheet. p = Project(path_proj_conf_file) sheet = p.build_sheet() # It should be a single-row DataFrame. assert isinstance(sheet, pd.DataFrame) assert 1 == len(sheet) assert 1 == p.num_samples # There will be additional values added from the Project, # but the core data values will have remained the same. sample = list(p.samples)[0] for attr, exp_val in zip(COLUMNS, values): obs_val = getattr(sample, attr) try: assert exp_val == obs_val except AssertionError as e: try: assert exp_val == int(obs_val) except AssertionError: raise e
def test_no_samples(self, protocols, delimiter, path_empty_project): """ Lack of Samples is unproblematic for the sheet build. """ # Regardless of protocol(s), the sheet should be empty. print("Test config file: {}".format(path_empty_project)) p = Project(path_empty_project) sheet = p.build_sheet(*protocols) assert sheet.empty
def test_multiple_samples( self, protocols, path_anns_file, path_proj_conf_file): """ Project also processes multiple Sample fine. """ p = Project(path_proj_conf_file) # Total sample count is constant. assert len(SAMPLE_NAMES) == sum(1 for _ in p.samples) # But the sheet permits filtering to specific protocol(s). exp_num_samples = len(SAMPLE_NAMES) if not protocols else \ sum(sum(1 for p2 in PROTOCOLS if p2 == p1) for p1 in protocols) sheet = p.build_sheet(*protocols) assert exp_num_samples == len(sheet) if protocols: def as_expected(sd): return sd.protocol in set(protocols) else: def as_expected(sd): return sd.protocol not in set(protocols) for _, sample_data in sheet.iterrows(): assert as_expected(sample_data)
def test_no_samples(self, protocols, delimiter, path_empty_project): """ Lack of Samples is unproblematic for the sheet build. """ # Regardless of protocol(s), the sheet should be empty. p = Project(path_empty_project) sheet = p.build_sheet(*protocols) assert sheet.empty