import sublime
import sublime_plugin
import os
import unittest
import StringIO
import sys

PROJECT_ROOT = os.path.dirname(__file__)
sys.path.append(os.path.join(PROJECT_ROOT, "tests"))

g_executing_test_suite = None

test_suites = {
    'objc_to_ruby_motion': ['objc_to_ruby_motion_tests', 'test_replace']
}


def print_to_view(view, obtain_content):
    edit = view.begin_edit()
    view.insert(edit, 0, obtain_content())
    view.end_edit(edit)
    view.set_scratch(True)
    view.set_name('unittest results')

    return view

class ShowObjcToRubyMotionTestsSuites(sublime_plugin.WindowCommand):

    def run(self):
        self.window.show_quick_panel(
            sorted(test_suites.keys()),
            self.run_suite
        )

    def run_suite(self, index):
        global g_executing_test_suite

        suite_name = sorted(test_suites.keys())[index]
        g_executing_test_suite = suite_name
        command_to_run = test_suites[suite_name][0]

        self.window.run_command(
            command_to_run,
            dict(suite_name=suite_name)
        )

class ObjcToRubyMotionTestsCommand(sublime_plugin.WindowCommand):

    def run(self, suite_name):
        bucket = StringIO.StringIO()
        suite_name = test_suites[suite_name][1]
        suite = unittest.defaultTestLoader.loadTestsFromName(suite_name)
        unittest.TextTestRunner(stream=bucket, verbosity=1).run(suite)

        print_to_view(self.window.new_file(), bucket.getvalue)

@@ -235,59 +235,67 @@
    '
-objc_to_ruby_motion': %5B'objc_to_ruby_motion_tests',
+all': 'all_test',%0A    'basic': 'test_basic',%0A    'convert':
  'te
@@ -305,17 +305,16 @@
 replace'
-%5D
 %0A%7D%0A%0A%0Adef
@@ -934,34 +934,35 @@
 n = 
-test_suites%5Bsuite_name%5D%5B0%5D
+'objc_to_ruby_motion_tests'
 %0A%0A  
@@ -1206,32 +1206,35 @@
 ingIO()%0A        
+if 
 suite_name = tes
@@ -1233,36 +1233,243 @@
 me =
- test_suites%5Bsuite_name%5D%5B1%5D%0A
+= 'all':%0A            suite_list = %5Bunittest.defaultTestLoader.loadTestsFromName(str) for str in test_suites.values()%5D%0A            suite = unittest.TestSuite(suite_list)%0A        else:%0A            file_name = test_suites%5Bsuite_name%5D%0A    
     
@@ -1525,20 +1525,19 @@
 romName(
-suit
+fil
 e_name)%0A

Change test runner to run test selectively