def test_no_derived_attributes(self, prj_data, exclude_derived_attributes): """ Passing Sample's project is equivalent to its inference. """ # Here we're disinterested in parameterization w.r.t. data source key, # so make it constant. src_key = self.SOURCE_KEYS[0] # Explicitly-passed object needs to at least be an AttMap. if exclude_derived_attributes: prj_data.pop("derived_attributes") sample_data = { SAMPLE_NAME_COLNAME: "arbitrary_sample", "prj": prj_data, DATA_SOURCE_COLNAME: src_key } sample_data = AttMap(sample_data) s = Sample(sample_data) assert not hasattr(s, src_key) assert src_key not in s # Create the samples and make the calls under test. s = Sample(sample_data) s.set_file_paths() # Check results. putative_new_attr = self.DATA_SOURCES[src_key] if exclude_derived_attributes: # The value to which the source key maps won't have been added. assert not hasattr(s, putative_new_attr) assert putative_new_attr not in s else: # The value to which the source key maps will have been added. assert putative_new_attr == getattr(s, DATA_SOURCE_COLNAME) assert putative_new_attr == s[DATA_SOURCE_COLNAME]
def test_no_derived_attributes(self, prj_data, exclude_derived_attributes): """ Passing Sample's project is equivalent to its inference. """ # Here we're disinterested in parameterization w.r.t. data source key, # so make it constant. src_key = self.SOURCE_KEYS[0] # Explicitly-passed object needs to at least be an AttMap. if exclude_derived_attributes: prj_data.pop("derived_attributes") sample_data = { SAMPLE_NAME_COLNAME: "arbitrary_sample", "prj": prj_data, DATA_SOURCE_COLNAME: src_key} sample_data = AttMap(sample_data) s = Sample(sample_data) assert not hasattr(s, src_key) assert src_key not in s # Create the samples and make the calls under test. s = Sample(sample_data) s.set_file_paths() # Check results. putative_new_attr = self.DATA_SOURCES[src_key] if exclude_derived_attributes: # The value to which the source key maps won't have been added. assert not hasattr(s, putative_new_attr) assert putative_new_attr not in s else: # The value to which the source key maps will have been added. assert putative_new_attr == getattr(s, DATA_SOURCE_COLNAME) assert putative_new_attr == s[DATA_SOURCE_COLNAME]
def test_prefers_explicit_project_context(self, prj_data): """ Explicit project data overrides any pre-stored project data. """ prj_data_modified = AttMap(copy.deepcopy(prj_data)) new_src = "src3" new_src_val = "newpath" assert new_src not in prj_data[DATA_SOURCES_SECTION] prj_data_modified[DATA_SOURCES_SECTION][new_src] = new_src_val sample_data = AttMap( {SAMPLE_NAME_COLNAME: "random-sample", "prj": prj_data, DATA_SOURCE_COLNAME: new_src}) s = Sample(sample_data) s.set_file_paths(prj_data_modified) assert new_src_val == getattr(s, DATA_SOURCE_COLNAME)
def test_prefers_explicit_project_context(self, prj_data): """ Explicit project data overrides any pre-stored project data. """ prj_data_modified = AttMap(copy.deepcopy(prj_data)) new_src = "src3" new_src_val = "newpath" assert new_src not in prj_data[DATA_SOURCES_SECTION] prj_data_modified[DATA_SOURCES_SECTION][new_src] = new_src_val sample_data = AttMap({ SAMPLE_NAME_COLNAME: "random-sample", "prj": prj_data, DATA_SOURCE_COLNAME: new_src }) s = Sample(sample_data) s.set_file_paths(prj_data_modified) assert new_src_val == getattr(s, DATA_SOURCE_COLNAME)
def test_equivalence_between_implicit_and_explicit_prj( self, prj_data, data_src_attr, src_key, explicit): """ Passing Sample's project is equivalent to its inference. """ # Explicitly-passed object needs to at least be an AttMap. sample_data = AttMap( {SAMPLE_NAME_COLNAME: "arbitrary_sample", "prj": prj_data, data_src_attr: src_key, "derived_attributes": [data_src_attr]}) # Create the samples and make the calls under test. s = Sample(sample_data) if explicit: s.set_file_paths(sample_data.prj) else: s.set_file_paths() # Check results. expected = self.DATA_SOURCES[src_key] observed = getattr(s, data_src_attr) assert expected == observed
def test_equivalence_between_implicit_and_explicit_prj( self, prj_data, data_src_attr, src_key, explicit): """ Passing Sample's project is equivalent to its inference. """ # Explicitly-passed object needs to at least be an AttMap. sample_data = AttMap({ SAMPLE_NAME_COLNAME: "arbitrary_sample", "prj": prj_data, data_src_attr: src_key, "derived_attributes": [data_src_attr] }) # Create the samples and make the calls under test. s = Sample(sample_data) if explicit: s.set_file_paths(sample_data.prj) else: s.set_file_paths() # Check results. expected = self.DATA_SOURCES[src_key] observed = getattr(s, data_src_attr) assert expected == observed