From 1e341f6f336156c2082e27f662efaeb8e869eadb Mon Sep 17 00:00:00 2001 From: ChrisKent Date: Fri, 29 Nov 2024 15:06:38 +0000 Subject: [PATCH] Updated tests --- tests/test_links.py | 10 +++---- tests/test_modify.py | 58 +++++++++++++++++++------------------- tests/test_regex.py | 66 -------------------------------------------- 3 files changed, 34 insertions(+), 100 deletions(-) diff --git a/tests/test_links.py b/tests/test_links.py index 40c7736..04c170f 100644 --- a/tests/test_links.py +++ b/tests/test_links.py @@ -4,7 +4,7 @@ class TestLinks(unittest.TestCase): - def test_add_link(self): + def test_link_add(self): links = Links() # Add a link to all correct linkfield @@ -17,21 +17,21 @@ def test_add_link(self): with self.assertRaises(AttributeError): links.append_link("invalid", linktoadd) - def test_remove_link(self): + def test_link_remove(self): linktoremove = "https://example.com" links = Links(protocols=[linktoremove]) # Remove the link from protocols - links.remove_link("protocols", linktoremove) + links.link_remove("protocols", linktoremove) self.assertEqual(links.protocols, []) # Remove a link from an incorrect linkfield with self.assertRaises(AttributeError): - links.remove_link("invalid", linktoremove) + links.link_remove("invalid", linktoremove) # Remove a link that is not in the linkfield with self.assertRaises(ValueError): - links.remove_link("protocols", linktoremove) + links.link_remove("protocols", linktoremove) if __name__ == "__main__": diff --git a/tests/test_modify.py b/tests/test_modify.py index 6eaccd5..e72af39 100644 --- a/tests/test_modify.py +++ b/tests/test_modify.py @@ -30,7 +30,7 @@ class TestAddAuthor(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_add_author_append(self): + def test_author_add_append(self): """Test adding an author to the Info object""" local_info = deepcopy(self.info) @@ -40,12 +40,12 @@ def test_add_author_append(self): self.assertNotIn(new_author, local_info.authors) # Append the author - local_info.add_author(new_author, None) + local_info.author_add(new_author, None) # Check the author is present at the end self.assertEqual(local_info.authors[-1], new_author) - def test_add_author_insert(self): + def test_author_add_insert(self): """Test adding an author to the Info object""" local_info = deepcopy(self.info) @@ -56,12 +56,12 @@ def test_add_author_insert(self): self.assertNotIn(new_author, local_info.authors) # Insert the author - local_info.add_author(new_author, new_index) + local_info.author_add(new_author, new_index) # Check the author is present at the index self.assertEqual(local_info.authors[new_index], new_author) - def test_add_author_invalid_index(self): + def test_author_add_invalid_index(self): """Test adding an author to the Info object with an invalid index""" local_info = deepcopy(self.info) @@ -72,7 +72,7 @@ def test_add_author_invalid_index(self): self.assertNotIn(new_author, local_info.authors) # Insert the author - local_info.add_author(new_author, new_index) + local_info.author_add(new_author, new_index) # Check the author is present at the end self.assertEqual(local_info.authors[-1], new_author) @@ -82,7 +82,7 @@ class TestRemoveAuthor(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_remove_author_valid(self): + def test_author_remove_valid(self): """Test removing an author from the Info object""" local_info = deepcopy(self.info) @@ -92,12 +92,12 @@ def test_remove_author_valid(self): self.assertIn(author_to_remove, local_info.authors) # Remove the author - local_info.remove_author(author_to_remove) + local_info.author_remove(author_to_remove) # Check the author is not present self.assertNotIn(author_to_remove, local_info.authors) - def test_remove_author_invalid(self): + def test_author_remove_invalid(self): """Test removing an author from the Info object""" local_info = deepcopy(self.info) @@ -108,14 +108,14 @@ def test_remove_author_invalid(self): # Remove the author with self.assertRaises(ValueError): - local_info.remove_author(author_to_remove) + local_info.author_remove(author_to_remove) class TestReorderAuthors(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_reorder_authors_valid(self): + def test_author_reorders_valid(self): """Test reordering authors in the Info object""" local_info = deepcopy(self.info) @@ -125,12 +125,12 @@ def test_reorder_authors_valid(self): self.assertEqual(local_info.authors, ["artic", "developer"]) # Reorder the authors - local_info.reorder_authors(new_order) + local_info.author_reorders(new_order) # Check the authors are in the correct order self.assertEqual(local_info.authors, ["developer", "artic"]) - def test_reorder_authors_invalid_index(self): + def test_author_reorders_invalid_index(self): """Test reordering authors in the Info object with an invalid index""" local_info = deepcopy(self.info) @@ -141,9 +141,9 @@ def test_reorder_authors_invalid_index(self): # Reorder the authors with self.assertRaises(IndexError): - local_info.reorder_authors(new_order) + local_info.author_reorders(new_order) - def test_reorder_authors_duplicate_index(self): + def test_author_reorders_duplicate_index(self): """Test reordering authors in the Info object with a duplicate index""" local_info = deepcopy(self.info) @@ -154,7 +154,7 @@ def test_reorder_authors_duplicate_index(self): # Reorder the authors with self.assertRaises(ValueError): - local_info.reorder_authors(new_order) + local_info.author_reorders(new_order) def test_no_authors_lost(self): """Test reordering authors in the Info object with a duplicate index""" @@ -166,7 +166,7 @@ def test_no_authors_lost(self): self.assertEqual(local_info.authors, ["artic", "developer"]) # Reorder the authors - local_info.reorder_authors(new_order) + local_info.author_reorders(new_order) # Check the authors are in the correct order self.assertEqual(local_info.authors, ["developer", "artic"]) @@ -176,7 +176,7 @@ class TestAddCitation(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_add_citation(self): + def test_citation_add(self): """Test adding a citation to the Info object""" local_info = deepcopy(self.info) @@ -186,7 +186,7 @@ def test_add_citation(self): self.assertNotIn(new_citation, local_info.citations) # Append the citation - local_info.add_citation(new_citation) + local_info.citation_add(new_citation) # Check the citation is present at the end self.assertIn(new_citation, local_info.citations) @@ -196,7 +196,7 @@ class TestRemoveCitation(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_remove_citation_valid(self): + def test_citation_remove_valid(self): """Test removing a citation from the Info object""" local_info = deepcopy(self.info) @@ -206,12 +206,12 @@ def test_remove_citation_valid(self): self.assertIn(citation_to_remove, local_info.citations) # Remove the citation - local_info.remove_citation(citation_to_remove) + local_info.citation_remove(citation_to_remove) # Check the citation is not present self.assertNotIn(citation_to_remove, local_info.citations) - def test_remove_citation_invalid(self): + def test_citation_remove_invalid(self): """Test removing a citation from the Info object""" local_info = deepcopy(self.info) @@ -222,14 +222,14 @@ def test_remove_citation_invalid(self): # Remove the citation with self.assertRaises(KeyError): - local_info.remove_citation(citation_to_remove) + local_info.citation_remove(citation_to_remove) class TestAddCollection(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_add_collection(self): + def test_collection_add(self): """Test adding a collection to the Info object""" local_info = deepcopy(self.info) @@ -239,7 +239,7 @@ def test_add_collection(self): self.assertNotIn(new_collection, local_info.collections) # Append the collection - local_info.add_collection(new_collection) + local_info.collection_add(new_collection) # Check the collection is present at the end self.assertIn(new_collection, local_info.collections) @@ -249,7 +249,7 @@ class TestRemoveCollection(unittest.TestCase): def setUp(self) -> None: self.info = base_info - def test_remove_collection_valid(self): + def test_collection_remove_valid(self): """Test removing a collection from the Info object""" local_info = deepcopy(self.info) @@ -259,12 +259,12 @@ def test_remove_collection_valid(self): self.assertIn(collection_to_remove, local_info.collections) # Remove the collection - local_info.remove_collection(collection_to_remove) + local_info.collection_remove(collection_to_remove) # Check the collection is not present self.assertNotIn(collection_to_remove, local_info.collections) - def test_remove_collection_invalid(self): + def test_collection_remove_invalid(self): """Test removing a collection from the Info object""" local_info = deepcopy(self.info) @@ -275,7 +275,7 @@ def test_remove_collection_invalid(self): # Remove the collection with self.assertRaises(KeyError): - local_info.remove_collection(collection_to_remove) + local_info.collection_remove(collection_to_remove) class TestChangeDescription(unittest.TestCase): diff --git a/tests/test_regex.py b/tests/test_regex.py index 28fd22c..cebd481 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -1,10 +1,5 @@ -import re import unittest -from primal_page.bedfiles import ( - V1_PRIMERNAME, - V2_PRIMERNAME, -) from primal_page.errors import ( InvalidSchemeID, InvalidSchemeName, @@ -90,67 +85,6 @@ def test_SchemeNamePattern_invalid(self): with self.assertRaises(InvalidSchemeName): validate_schemename(name) - def test_V1PrimerName_ValidNames(self): - """ - Tests main/V1_PRIMERNAME for valid primer names - """ - valid_names = [ - "artic-nCoV_1_LEFT", - "mpx_1_RIGHT", - "artic-nCoV_100_LEFT_alt", - "marv-2023_100_RIGHT_ALT", - "artic-nCoV_1_LEFT", - ] - - for name in valid_names: - self.assertTrue(re.match(V1_PRIMERNAME, name)) - - def test_V1PrimerName_InvalidNames(self): - """ - Tests main/V1_PRIMERNAME for invalid primer names - """ - invalid_names = [ - "artic-nCoV_1_LEFT_0", # V2 format should fail - "artic_nCoV_1_LEFT", # to many _ - "artic*nCoV_100_LEFT_99", # invalid character - "marv-2023_RIGHT_2", # missing amplicion number - "artic-nCoV_-1_LEFT_alt", # Negative amplicon number - ] - - for name in invalid_names: - self.assertFalse(re.match(V1_PRIMERNAME, name)) - - def test_V2PrimerName_ValidNames(self): - """ - Tests main/V2_PRIMERNAME for valid primer names - """ - valid_names = [ - "artic-nCoV_1_LEFT_0", - "mpx_1_RIGHT_100", - "artic-nCoV_100_LEFT_99", - "marv-2023_100_RIGHT_2", - "artic-nCoV_1_LEFT_1", - ] - - for name in valid_names: - self.assertTrue(re.match(V2_PRIMERNAME, name)) - - def test_V2PrimerName_InvalidNames(self): - """ - Tests main/V2_PRIMERNAME for invalid primer names - """ - invalid_names = [ - "artic-nCoV_1_LEFT", # V1 format should fail - "artic_nCoV_1_LEFT_0", # to many _ - "artic*nCoV_100_LEFT_99", # invalid character - "marv-2023_RIGHT_2", # missing amplicion number - "artic-nCoV_-1_LEFT_0", # Negative amplicon number - "marv-2023_1_RIGHT_2_alt", # alt should fail - ] - - for name in invalid_names: - self.assertFalse(re.match(V2_PRIMERNAME, name)) - class TestNotEmpty(unittest.TestCase): def test_not_empty_full(self):