Skip to content

Commit

Permalink
change class method to static method (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Jul 11, 2023
1 parent aad7a52 commit 5efcba1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/nplinker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _load_strain_mappings(self):
self.strains.generate_strain_mappings(self.strain_mappings_file,
self.antismash_dir)
else:
sc = StrainCollection().read_json(self.strain_mappings_file)
sc = StrainCollection.read_json(self.strain_mappings_file)
for strain in sc:
self.strains.add(strain)
logger.info('Loaded dataset strain IDs ({} total)'.format(
Expand Down
6 changes: 3 additions & 3 deletions src/nplinker/strain_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def lookup(self, name: str) -> Strain:
return self._strain_dict_name[name]
raise KeyError(f"Strain {name} not found in strain collection.")

@classmethod
def read_json(cls, file: str | PathLike) -> 'StrainCollection':
@staticmethod
def read_json(file: str | PathLike) -> 'StrainCollection':
"""Read a strain mappings JSON file and return a StrainCollection object.
Args:
Expand All @@ -123,7 +123,7 @@ def read_json(cls, file: str | PathLike) -> 'StrainCollection':
with open(file, 'r') as f:
json_data = json.load(f)

strain_collection = cls()
strain_collection = StrainCollection()
for data in json_data['strain_mappings']:
strain = Strain(data['strain_id'])
for alias in data['strain_alias']:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def spec_dict() -> dict[str, Spectrum]:
@pytest.fixture
def collection_from_file() -> StrainCollection:
filename = DATA_DIR / STRAIN_MAPPINGS_FILENAME
sut = StrainCollection().read_json(filename)
sut = StrainCollection.read_json(filename)
return sut


Expand Down
2 changes: 1 addition & 1 deletion tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ def test_load_strain_mappings(config):
sut._load_strain_mappings()

actual = sut.strains
expected = StrainCollection().read_json(sut.strain_mappings_file)
expected = StrainCollection.read_json(sut.strain_mappings_file)

assert actual == expected

0 comments on commit 5efcba1

Please sign in to comment.