from os import path

import liveandletdie
from selenium import webdriver

try:
    import unittest2 as unittest
except ImportError:
    import unittest


def abspath(pth):
    return path.join(path.dirname(__file__), '../..', pth)


PORT = 8001


class Base(unittest.TestCase):
    EXPECTED_TEXT = None
    app = None
    
    @classmethod
    def setUpClass(cls):
        try:
            # Run the live server.
            cls.app.live(kill=True)
        except Exception as e:
            # Skip test if not started.
            raise unittest.SkipTest(e.message)
        
        # Start browser.
        cls.browser = webdriver.Firefox()
        cls.browser.implicitly_wait(3)
    
    @classmethod
    def tearDownClass(cls):
        # Stop server.
        cls.app.die()
         
        # Stop browser.
        if hasattr(cls, 'browser'):
            cls.browser.quit()
    
    def test_visit_start_page(self):
        self.browser.get(self.app.url)
        page_text = self.browser.find_element_by_tag_name('body').text
        self.assertIn(self.EXPECTED_TEXT, page_text)


class TestFlask(Base):
    EXPECTED_TEXT = 'Home Flask'
    app = liveandletdie.Flask(abspath('sample_apps/flask/main.py'), port=PORT)


class TestPyramid(Base):
    EXPECTED_TEXT = 'Home Pyramid'
    app = liveandletdie.WsgirefSimpleServer(abspath('sample_apps/pyramid/main.py'), port=PORT)


class TestDjango(Base):
    EXPECTED_TEXT = 'Home Django'
    app = liveandletdie.Django(abspath('sample_apps/django/example'), port=PORT)


class TestGAE(Base):
    EXPECTED_TEXT = 'Home GAE'
    app = liveandletdie.GAE(abspath('venv/bin/dev_appserver'),
                  abspath('sample_apps/gae'), port=PORT, kill_orphans=True)


if __name__ == '__main__':
    unittest.main()
@@ -244,83 +244,32 @@
 1%0A%0A%0A
-class Base(unittest.TestCase):%0A    EXPECTED_TEXT = None%0A    app = None%0A    
+def test_decorator(cls):
 %0A   
@@ -473,16 +473,18 @@
         
+ #
  raise u
@@ -511,16 +511,36 @@
 essage)%0A
+            raise e%0A
         
@@ -1048,16 +1048,172 @@
 _text)%0A%0A
+    cls.setUpClass = setUpClass%0A    cls.tearDownClass = tearDownClass%0A    cls.test_visit_start_page = test_visit_start_page%0A    return cls%0A%0A%0A@test_decorator
 %0Aclass T
@@ -1221,17 +1221,30 @@
 stFlask(
-B
+unittest.TestC
 ase):%0A  
@@ -1347,32 +1347,48 @@
 ), port=PORT)%0A%0A%0A
+@test_decorator%0A
 class TestPyrami
@@ -1389,17 +1389,30 @@
 Pyramid(
-B
+unittest.TestC
 ase):%0A  
@@ -1533,32 +1533,48 @@
 ), port=PORT)%0A%0A%0A
+@test_decorator%0A
 class TestDjango
@@ -1574,17 +1574,30 @@
 tDjango(
-B
+unittest.TestC
 ase):%0A  
@@ -1715,23 +1715,52 @@
 )%0A%0A%0A
-class TestGAE(B
+@test_decorator%0Aclass TestGAE(unittest.TestC
 ase)
@@ -1979,8 +1979,9 @@
 t.main()
+%0A

Fix useless test of Base unittest class