<commit_before>from Tkinter import *
from subprocess import call

from testSuite import SahanaTestSuite
import thread
import unittest

import os
import thread
import time
from subprocess import Popen

class TestWindow(Frame):

    def runTestSuite(self):
        SahanaTestSuite.startSelenium(self.radioB.get(),
                                      self.browserPath.get(),
                                      self.ipAddr.get(),
                                      self.ipPort.get(),
                                      self.URL.get()
                                     )
        SahanaTestSuite.setSahanaAdminDetails(self.adminUser.get(),
                                              self.adminPassword.get(),
                                             )
        self.clean = False
        test = SahanaTestSuite()
        test.test_main(self.getTestModules())
        call(["firefox", "../results/regressionTest.html"])
        SahanaTestSuite.stopSelenium() # Debug comment out to keep the Selenium window open 
        self.clean = True
    
    def __del__(self):
        if (not self.clean):
            SahanaTestSuite.stopSelenium()

    def isSeleniumRunning(self):
        if sys.platform[:5]=='linux':
            # Need to find if a service is running on the Selenium port 
            sockets = os.popen("netstat -lnt").read()
            # look for match on IPAddr and port
            service = ":%s" % (self.ipPort.get())
            if (service in sockets):
                return True
            else:
                return False
        if self.seleniumServer != 0:
            return True
    
    def sahanaPanel(self, panel):
        Label(panel, text="Sahana options").pack(side=TOP)
        Label(panel, text="To run the tests a user with admin rights needs to be provided.").pack(side=TOP, anchor=W)
        Label(panel, text="If this is left blank then the user of <EMAIL> will be used.").pack(side=TOP, anchor=W)
        detailPanel = Frame(panel)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        Label(detailPanel, text="User name:").grid(row=0,column=0, sticky=NW)
        self.adminUser = Entry(detailPanel, width=30)
        self.adminUser.grid(row=0,column=1, sticky=NW)
        Label(detailPanel, text="Password:").grid(row=1,column=0, sticky=NW)
        self.adminPassword = Entry(detailPanel, show="*", width=16)
        self.adminPassword.grid(row=1,column=1, sticky=NW)
        Label(detailPanel, text="Sahana URL:").grid(row=2,column=0, sticky=NW)
        self.URL = Entry(detailPanel, width=40)
        self.URL.grid(row=2,column=1, sticky=NW)
        self.URL.insert(0, "http://127.0.0.1:8000/")
        
    # a file with test details listed per line, with the format being:
    # <display name>, <dotted notation of the test>
    # any line not meeting this criteria will be ignored.
    # <dotted notation of the test> is:
    # module optionally followed by the class name optionally followed by the method
    # OR: module[.class[.method]]
    def getTestModuleDetails(self):
        source = open("../data/testModules.txt", "r")
        modules = source.readlines()
        source.close()
        moduleList =[]
        for module in modules:
            details = module.split(',')
            if len(details) == 2:
                moduleList.append((details[0].strip(),details[1].strip()))
        return tuple(moduleList)

    def getTestModules(self):
        i = 0
        testModuleList = []
        for module in self.checkboxModules:
            if module.get()==1:
                testModuleList.append(self.moduleList[i][1].strip())
            i+=1
        return tuple(testModuleList)
        
    def testModulepanel(self, panel):
        self.moduleList = self.getTestModuleDetails()
        Label(panel, text="Test Modules").pack(side=TOP)
        Label(panel, text="Select the test modules that you would like to run.").pack(side=TOP, anchor=W)
        detailPanel = Frame(panel)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        self.checkboxModules = []
        i = 0
        for module in self.moduleList:
            var=IntVar()
            chk = Checkbutton(detailPanel, text=module[0], variable=var)
            self.checkboxModules.append(var)
            chk.grid(row=i, column=0, sticky=NW)
            i+=1
        
    def serverStatus(self, event):
        if (self.ipAddr.get() != '127.0.0.1'):
            self.statusLbl.config(text="Unknown")
            self.stopSelenium.config(state="disabled")
            self.startSelenium.config(state="disabled")
        elif self.isSeleniumRunning():
            self.statusLbl.config(text="Running")
            self.stopSelenium.config(state="active")
            self.startSelenium.config(state="disabled")
        else:
            self.statusLbl.config(text="Stopped")
            self.stopSelenium.config(state="disabled")
            self.startSelenium.config(state="active")
        self.updateServerCommand()
            
    def serverPanel(self, panel):
        Label(panel, text="Selenium server options").pack(side=TOP)
        detailPanel = Frame(panel)
        detailPanel.columnconfigure(0,weight=0)
        detailPanel.columnconfigure(1,weight=1)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        Label(detailPanel, text="Status:").grid(row=0,column=0, sticky=NW)
        self.statusLbl = Label(detailPanel, text="Unknown")
        self.statusLbl.grid(row=0,column=1, sticky=NW)
        Label(detailPanel, text="IP Address:").grid(row=1,column=0, sticky=NW)
        self.ipAddr = Entry(detailPanel, width=16)
        self.ipAddr.insert(0,"127.0.0.1")
        self.ipAddr.grid(row=1,column=1, sticky=NW)
        Label(detailPanel, text="Port:").grid(row=2,column=0, sticky=NW)
        self.ipPort = Entry(detailPanel, width=6)
        self.ipPort.insert(0,"4444")
        self.ipPort.grid(row=2,column=1, sticky=NW)
        self.ipAddr.bind("<FocusOut>", self.serverStatus)
        self.ipPort.bind("<FocusOut>", self.serverStatus)
        Label(detailPanel, text="Logging:").grid(row=4,column=0, sticky=NW)
        logPanel = Frame(detailPanel)
        logPanel.grid(row=4,column=1, sticky=NSEW)
        self.radioLog = StringVar()
        Radiobutton(logPanel, text="No Logging", value="None", command=self.onPressServerLog, variable=self.radioLog).pack(side=TOP, anchor = W)
        Radiobutton(logPanel, text="Log to file", value="File", command=self.onPressServerLog, variable=self.radioLog).pack(side=TOP, anchor = W)
        self.logFilename = Entry(logPanel, width=40)
        self.logFilename.insert(0,"SahanaEdenRegressionTests.log")
        self.logFilename.config(state='readonly')
        self.logFilename.pack(side=TOP, anchor=W, expand=YES, fill=X)
        self.radioLog.set("None")
        self.serverCommand = Entry(detailPanel, state='readonly', width=50)
        self.serverCommand.grid(row=5,column=0, columnspan=2, sticky=NSEW)
        self.updateServerCommand()
        button = Frame(logPanel)
        button.pack(side=TOP, fill=BOTH)
        self.startSelenium = Button(button, text='Start', command=self.startSelenium)
        self.startSelenium.pack(side=RIGHT, anchor=SE)
        self.stopSelenium = Button(button, text='Stop', command=self.stopSelenium)
        self.stopSelenium.pack(side=RIGHT, anchor=SE)

        self.serverStatus(Event())

    def updateServerCommand(self):
        args = self.buildServerStartCommand()
        self.serverCommand.config(state='normal')
        self.serverCommand.delete(0, len(self.serverCommand.get()))
        self.serverCommand.insert(0, args)
        self.serverCommand.config(state='readonly')
        
    def buildServerStartCommand(self):
        if os.environ.has_key('JAVA_HOME'):
            java = os.path.join(os.environ['JAVA_HOME'],"java")
        else:
            java = "java"
        args = [java, r"-jar", r"selenium-server.jar", r"-singlewindow", "-port", "%s" % self.ipPort.get()]
        if self.radioLog.get() == "File":
            args.append("-log")
            args.append(self.logFilename.get())
        return tuple(args)
        
    def startSelenium(self):
        # start the Selenium server
        os.chdir(r'../server/')
        args = self.buildServerStartCommand()
        self.startSelenium.config(state="disabled")
        self.seleniumServer = Popen(args)
        # crude wait to give the server time to start
        os.chdir(r'../scripts/')
        time.sleep(5)
        self.serverStatus(Event())<commit_msg>fix java path JAVA_HOME/bin/java<commit_after>from Tkinter import *
from subprocess import call

from testSuite import SahanaTestSuite
import thread
import unittest

import os
import thread
import time
from subprocess import Popen

class TestWindow(Frame):

    def runTestSuite(self):
        SahanaTestSuite.startSelenium(self.radioB.get(),
                                      self.browserPath.get(),
                                      self.ipAddr.get(),
                                      self.ipPort.get(),
                                      self.URL.get()
                                     )
        SahanaTestSuite.setSahanaAdminDetails(self.adminUser.get(),
                                              self.adminPassword.get(),
                                             )
        self.clean = False
        test = SahanaTestSuite()
        test.test_main(self.getTestModules())
        call(["firefox", "../results/regressionTest.html"])
        SahanaTestSuite.stopSelenium() # Debug comment out to keep the Selenium window open 
        self.clean = True
    
    def __del__(self):
        if (not self.clean):
            SahanaTestSuite.stopSelenium()

    def isSeleniumRunning(self):
        if sys.platform[:5]=='linux':
            # Need to find if a service is running on the Selenium port 
            sockets = os.popen("netstat -lnt").read()
            # look for match on IPAddr and port
            service = ":%s" % (self.ipPort.get())
            if (service in sockets):
                return True
            else:
                return False
        if self.seleniumServer != 0:
            return True
    
    def sahanaPanel(self, panel):
        Label(panel, text="Sahana options").pack(side=TOP)
        Label(panel, text="To run the tests a user with admin rights needs to be provided.").pack(side=TOP, anchor=W)
        Label(panel, text="If this is left blank then the user of <EMAIL> will be used.").pack(side=TOP, anchor=W)
        detailPanel = Frame(panel)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        Label(detailPanel, text="User name:").grid(row=0,column=0, sticky=NW)
        self.adminUser = Entry(detailPanel, width=30)
        self.adminUser.grid(row=0,column=1, sticky=NW)
        Label(detailPanel, text="Password:").grid(row=1,column=0, sticky=NW)
        self.adminPassword = Entry(detailPanel, show="*", width=16)
        self.adminPassword.grid(row=1,column=1, sticky=NW)
        Label(detailPanel, text="Sahana URL:").grid(row=2,column=0, sticky=NW)
        self.URL = Entry(detailPanel, width=40)
        self.URL.grid(row=2,column=1, sticky=NW)
        self.URL.insert(0, "http://127.0.0.1:8000/")
        
    # a file with test details listed per line, with the format being:
    # <display name>, <dotted notation of the test>
    # any line not meeting this criteria will be ignored.
    # <dotted notation of the test> is:
    # module optionally followed by the class name optionally followed by the method
    # OR: module[.class[.method]]
    def getTestModuleDetails(self):
        source = open("../data/testModules.txt", "r")
        modules = source.readlines()
        source.close()
        moduleList =[]
        for module in modules:
            details = module.split(',')
            if len(details) == 2:
                moduleList.append((details[0].strip(),details[1].strip()))
        return tuple(moduleList)

    def getTestModules(self):
        i = 0
        testModuleList = []
        for module in self.checkboxModules:
            if module.get()==1:
                testModuleList.append(self.moduleList[i][1].strip())
            i+=1
        return tuple(testModuleList)
        
    def testModulepanel(self, panel):
        self.moduleList = self.getTestModuleDetails()
        Label(panel, text="Test Modules").pack(side=TOP)
        Label(panel, text="Select the test modules that you would like to run.").pack(side=TOP, anchor=W)
        detailPanel = Frame(panel)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        self.checkboxModules = []
        i = 0
        for module in self.moduleList:
            var=IntVar()
            chk = Checkbutton(detailPanel, text=module[0], variable=var)
            self.checkboxModules.append(var)
            chk.grid(row=i, column=0, sticky=NW)
            i+=1
        
    def serverStatus(self, event):
        if (self.ipAddr.get() != '127.0.0.1'):
            self.statusLbl.config(text="Unknown")
            self.stopSelenium.config(state="disabled")
            self.startSelenium.config(state="disabled")
        elif self.isSeleniumRunning():
            self.statusLbl.config(text="Running")
            self.stopSelenium.config(state="active")
            self.startSelenium.config(state="disabled")
        else:
            self.statusLbl.config(text="Stopped")
            self.stopSelenium.config(state="disabled")
            self.startSelenium.config(state="active")
        self.updateServerCommand()
            
    def serverPanel(self, panel):
        Label(panel, text="Selenium server options").pack(side=TOP)
        detailPanel = Frame(panel)
        detailPanel.columnconfigure(0,weight=0)
        detailPanel.columnconfigure(1,weight=1)
        detailPanel.pack(side=TOP, anchor=W, fill=X)
        Label(detailPanel, text="Status:").grid(row=0,column=0, sticky=NW)
        self.statusLbl = Label(detailPanel, text="Unknown")
        self.statusLbl.grid(row=0,column=1, sticky=NW)
        Label(detailPanel, text="IP Address:").grid(row=1,column=0, sticky=NW)
        self.ipAddr = Entry(detailPanel, width=16)
        self.ipAddr.insert(0,"127.0.0.1")
        self.ipAddr.grid(row=1,column=1, sticky=NW)
        Label(detailPanel, text="Port:").grid(row=2,column=0, sticky=NW)
        self.ipPort = Entry(detailPanel, width=6)
        self.ipPort.insert(0,"4444")
        self.ipPort.grid(row=2,column=1, sticky=NW)
        self.ipAddr.bind("<FocusOut>", self.serverStatus)
        self.ipPort.bind("<FocusOut>", self.serverStatus)
        Label(detailPanel, text="Logging:").grid(row=4,column=0, sticky=NW)
        logPanel = Frame(detailPanel)
        logPanel.grid(row=4,column=1, sticky=NSEW)
        self.radioLog = StringVar()
        Radiobutton(logPanel, text="No Logging", value="None", command=self.onPressServerLog, variable=self.radioLog).pack(side=TOP, anchor = W)
        Radiobutton(logPanel, text="Log to file", value="File", command=self.onPressServerLog, variable=self.radioLog).pack(side=TOP, anchor = W)
        self.logFilename = Entry(logPanel, width=40)
        self.logFilename.insert(0,"SahanaEdenRegressionTests.log")
        self.logFilename.config(state='readonly')
        self.logFilename.pack(side=TOP, anchor=W, expand=YES, fill=X)
        self.radioLog.set("None")
        self.serverCommand = Entry(detailPanel, state='readonly', width=50)
        self.serverCommand.grid(row=5,column=0, columnspan=2, sticky=NSEW)
        self.updateServerCommand()
        button = Frame(logPanel)
        button.pack(side=TOP, fill=BOTH)
        self.startSelenium = Button(button, text='Start', command=self.startSelenium)
        self.startSelenium.pack(side=RIGHT, anchor=SE)
        self.stopSelenium = Button(button, text='Stop', command=self.stopSelenium)
        self.stopSelenium.pack(side=RIGHT, anchor=SE)

        self.serverStatus(Event())

    def updateServerCommand(self):
        args = self.buildServerStartCommand()
        self.serverCommand.config(state='normal')
        self.serverCommand.delete(0, len(self.serverCommand.get()))
        self.serverCommand.insert(0, args)
        self.serverCommand.config(state='readonly')
        
    def buildServerStartCommand(self):
        if os.environ.has_key('JAVA_HOME'):
            java = os.path.join(os.environ['JAVA_HOME'], "bin", "java")
        else:
            java = "java"
        args = [java, r"-jar", r"selenium-server.jar", r"-singlewindow", "-port", "%s" % self.ipPort.get()]
        if self.radioLog.get() == "File":
            args.append("-log")
            args.append(self.logFilename.get())
        return tuple(args)
        
    def startSelenium(self):
        # start the Selenium server
        os.chdir(r'../server/')
        args = self.buildServerStartCommand()
        self.startSelenium.config(state="disabled")
        self.seleniumServer = Popen(args)
        # crude wait to give the server time to start
        os.chdir(r'../scripts/')
        time.sleep(5)
        self.serverStatus(Event())
{'fraction_non_alphanumeric': 0.12791312004696215, 'fraction_numerical': 0.01103610214264749, 'mean_word_length': 2.4443995147594015, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4111640', 'n_tokens_mistral': 5183, 'n_tokens_neox': 4997, 'n_words': 970}