import sublime
from unittest import TestCase
import os, re, shutil

__dir__ = os.path.dirname(os.path.abspath(__file__))
outputdir = os.path.join(sublime.packages_path(), 'User', 'UnitTesting', "tests_output")

class TestUnitTesting(TestCase):

    def test_success(self):
        try:
            shutil.copytree(os.path.join(__dir__, "_Success"), os.path.join(sublime.packages_path(),"_Success"))
        except:
            pass
        sublime.run_command("unit_testing", {"package":"_Success", "async":False})
        with open(os.path.join(outputdir, "_Success"), 'r') as f:
            txt = f.read()
        m = re.search('^OK',txt, re.MULTILINE)
        shutil.rmtree(os.path.join(sublime.packages_path(),"_Success"))
        self.assertEqual(hasattr(m,"group"), True)

    def test_failure(self):
        try:
            shutil.copytree(os.path.join(__dir__, "_Failure"), os.path.join(sublime.packages_path(),"_Failure"))
        except:
            pass
        sublime.run_command("unit_testing", {"package":"_Failure", "async":False})
        with open(os.path.join(outputdir, "_Failure"), 'r') as f:
            txt = f.read()
        m = re.search('^FAILED \(failures=1\)',txt, re.MULTILINE)
        shutil.rmtree(os.path.join(sublime.packages_path(),"_Failure"))
        self.assertEqual(hasattr(m,"group"), True)

    def test_error(self):
        # Run unittesting for an non existing package
        sublime.run_command("unit_testing", {"package":"_Error", "async":False})
        with open(os.path.join(outputdir, "_Error"), 'r') as f:
            txt = f.read()
        m = re.search('^ERROR',txt, re.MULTILINE)
        self.assertEqual(hasattr(m,"group"), True)

@@ -238,16 +238,280 @@
 Case):%0A%0A
+    def setUp(self):%0A        self.view = sublime.active_window().new_file()%0A%0A    def tearDown(self):%0A        if self.view and len(sublime.active_window().views())%3E1:%0A            self.view.set_scratch(True)%0A            self.view.window().run_command(%22close_file%22)%0A%0A
     def 

fix bug for osx test, make sure at least one window