diff --git a/Makefile b/Makefile index e11e752..8cbf3fe 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,6 @@ test: $(NODE_BIN)/yamllint data/*.yml $(NODE_BIN)/yamllint config.yml $(NODE_BIN)/mdspell --en-gb -ranx 'content/**/*.*' - nose2 - .PHONY: build clean install test diff --git a/requirements.txt b/requirements.txt index c960a34..f7d24cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,2 @@ -beautifulsoup4==4.6.0 -nose2==0.6.5 pygments -pyyaml==3.12 diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 324f23a..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,50 +0,0 @@ -import unittest -import os.path -from bs4 import BeautifulSoup -import yaml - -SETTINGS = yaml.safe_load(open(os.path.realpath('./config.yml'))) - - -class TestClient: - output_path = os.path.realpath('./public') - - def get(self, path, JS=True): - file_path = self.build_path(path) - content = "".join(open(file_path).readlines()) - if file_path.endswith('html'): - content = BeautifulSoup(content, 'html.parser') - if JS: - for script in content(["noscript"]): # Remove noscript tags - script.extract() - return content - - def build_path(self, path): - if path.startswith(SETTINGS['baseURL']): - path = path.replace(SETTINGS['baseURL'], '') - if path.startswith('/'): - path = path[1:] - if path.endswith('/'): - path += 'index.html' - return os.path.join(self.output_path, path) - - def exists(self, path): - return os.path.exists(self.build_path(path)) - - -class TestCase(unittest.TestCase): - client = TestClient() - settings = SETTINGS - - def get_children(self, content): - return str(list(content.children)[0]).strip() - - def assertTitle(self, content, title): - self.assertIn(title, content.title.string) - - def assertHeaderTitle(self, content, title): - header_title = content.find('header').find('h2') - self.assertIn(title, self.get_children(header_title)) - - def assertSamePath(self, p1, p2): - self.assertEqual(self.client.build_path(p1), self.client.build_path(p2)) diff --git a/tests/tests_common.py b/tests/tests_common.py deleted file mode 100644 index 181ea43..0000000 --- a/tests/tests_common.py +++ /dev/null @@ -1,57 +0,0 @@ -from tests import TestCase -from bs4 import BeautifulSoup - - -class CorePagesTestCase(TestCase): - def test_has_index(self): - content = self.client.get('index.html') - self.assertTitle(content, 'Homepage') - - def test_has_sitemap(self): - self.assertTrue(self.client.exists('sitemap.xml')) - - def test_has_atom_feed(self): - self.assertTrue(self.client.exists('index.xml')) - - def test_has_robots(self): - self.assertTrue(self.client.exists('robots.txt')) - - -class CommonPagesTestCase(TestCase): - def test_navbar_links(self): - content = self.client.get('index.html') - tabs = content.find('nav').find_all('li', class_="top-level") - self.assertEqual(len(tabs), 6) - for tab in tabs: - if len(tab.find_all('a')) == 1: - self.assertEqual(len(tab.find_all('ul')), 0) - self.assertTrue(self.client.exists(tab.find('a').attrs['href'])) - else: - self.assertLessEqual(len(tab.find_all('a')), self.settings['params']['nav_items'] + 2) - for link in tab.find_all('a'): - self.assertTrue(self.client.exists(link.attrs['href'])) - self.assertNotEqual(self.get_children(link), '') - if self.get_children(link) == 'See more': - self.assertEqual(link.attrs['href'], tab.find_all('a')[0].attrs['href']) - - -class TestClientTestCase(TestCase): - def test_client_fails(self): - with self.assertRaises(FileNotFoundError): - self.client.get('foo.bar') - - def test_client_gets_data(self): - content = self.client.get('index.html') - self.assertIsInstance(content, BeautifulSoup) - - def test_file_exists(self): - self.assertTrue(self.client.exists('index.html')) - - def test_build_path_without_index(self): - self.assertEqual( - self.client.build_path('foo/'), - self.client.build_path('foo/index.html') - ) - - def test_file_doesnt_exist(self): - self.assertFalse(self.client.exists('foo.bar')) diff --git a/tests/tests_pages.py b/tests/tests_pages.py deleted file mode 100644 index 0200c3b..0000000 --- a/tests/tests_pages.py +++ /dev/null @@ -1,17 +0,0 @@ -from tests import TestCase - - -class IndexPageTestCase(TestCase): - def test_index_sections(self): - for section in ['projects', 'recent-posts']: - content = self.client.get('index.html') - rows = content.find('div', id=section).find_all('div', class_='row') - self.assertLessEqual(len(rows), self.settings['params']['index_items']) - self.assertGreater(self.settings['params']['index_items'], 0) - for row in rows: - self.assertIsNotNone(row.find('section', class_='box')) - self.assertTrue(self.client.exists(row.find('a').attrs['href'])) - self.assertNotEqual(self.get_children(row.find('p')), '') - self.assertLessEqual(len(self.get_children(row.find('p'))), self.settings['params']['summary_length'] + 3) - self.assertNotEqual(self.get_children(row.find('h3')), '') -