Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisgKent committed Nov 29, 2024
1 parent e8868da commit 1e341f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 100 deletions.
10 changes: 5 additions & 5 deletions tests/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__":
Expand Down
58 changes: 29 additions & 29 deletions tests/test_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"""
Expand All @@ -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"])
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand Down
66 changes: 0 additions & 66 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import re
import unittest

from primal_page.bedfiles import (
V1_PRIMERNAME,
V2_PRIMERNAME,
)
from primal_page.errors import (
InvalidSchemeID,
InvalidSchemeName,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1e341f6

Please sign in to comment.