diff --git a/pymispgalaxies/__init__.py b/pymispgalaxies/__init__.py index 795d66f..139bff8 100644 --- a/pymispgalaxies/__init__.py +++ b/pymispgalaxies/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from .api import Galaxies, Clusters, EncodeGalaxies +from .api import Galaxies, Clusters, EncodeGalaxies, UnableToRevertMachinetag diff --git a/pymispgalaxies/api.py b/pymispgalaxies/api.py index 179ddb3..6ab4e17 100644 --- a/pymispgalaxies/api.py +++ b/pymispgalaxies/api.py @@ -244,8 +244,8 @@ class Clusters(collections.Mapping): return [cluster.machinetags() for cluster in self.values()] def revert_machinetag(self, machinetag): - _, cluster_type, cluster_value = re.findall('^([^:]*):([^=]*)="([^"]*)"$', machinetag)[0] try: + _, cluster_type, cluster_value = re.findall('^([^:]*):([^=]*)="([^"]*)"$', machinetag)[0] cluster = self.get(cluster_type) value = cluster[cluster_value] return cluster, value diff --git a/tests/tests.py b/tests/tests.py index 5e53b9b..9a88bde 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import unittest -from pymispgalaxies import Galaxies, Clusters +from pymispgalaxies import Galaxies, Clusters, UnableToRevertMachinetag from glob import glob import os import json @@ -59,6 +59,8 @@ class TestPyMISPGalaxies(unittest.TestCase): def test_revert_machinetag(self): self.assertEqual(len(self.clusters.revert_machinetag('misp-galaxy:tool="Babar"')), 2) + with self.assertRaises(UnableToRevertMachinetag): + self.clusters.revert_machinetag('blah') def test_len(self): self.assertIsNot(len(self.clusters), 0)