<commit_before>#!/usr/bin/python

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import subprocess

import os, cgi

FEATURES_FOLDER = "src/features"

SCENARIO_TEMPLATE = """
<li>
  %(name)s <input type="submit" name="action:%(feature)s:%(lineno)d" value="Run" />
</li>
"""

FEATURE_TEMPLATE = """
<li>
  <h3>%(name)s <input type="submit" name="action:%(feature)s" value="Run" /></h3>
  <ul class="scenarios">
    %(scenarios)s
  </ul>
</li>
"""

PAGE_TEMPLATE = """
<!DOCTYPE html>
<html>
  <head>
    <title>Cucumber test runner</title>
    <style>
      body {
        color: #333;
        font-size: 90%%;
        font-family: sans-serif;
      }

      ul {
        list-style:none;
        padding-left:5px;
        font-size:10px;
        line-height:26px;
      }

      ul li {
        display:block;
        height:26px;
        border-top:1px solid #eee;
        clear:both;
      }

      ul.scenarios li:nth-child(2n+1) {
        background:#eeffff;
      }
    
      ul li input {
        float:right;
      }

      #features > li {
        height:50px; 
      }

      #feature-container {
        width:50%%;
        float:left;
      }

      #output-container {
        width:45%%;
        float:left;
        margin-left:4%%;
      }
      #output-container textarea {
        height: 400px;
        width:100%%;
      } 
    </style>
  </head>
  <body>
    <div id="feature-container">
      <h3>Features:</h3>
      <form action="" method="POST">
        <p><input type="checkbox" name="external-server" %(external_checkbox)s /> run with external server. <input type="submit" name="action:%(features_folder)s" value="Run all" style="float:right;"/></p>
        <ul id="features">
          %(features)s
        </ul>
      </form>
    </div>
    <div id="output-container">
      <h3>Output:</h3>
      <textarea>%(console_output)s</textarea>
    </div>
  </body>
</html>
"""

class Handler(BaseHTTPRequestHandler):

    def parse_feature_file(self, path):
      
      feature_name = path
      scenarios = []

      f = open(path)
      line = f.readline()
      lineno = 1
      while (line != ""):
        
        if line.strip().startswith("Feature:"):
          feature_name = line.strip()[9:].strip()

        if line.strip().startswith("Scenario:"):
          scenarios.append( (line.strip()[9:].strip(), lineno) )

        lineno += 1
        line = f.readline()

      return (feature_name, path, sorted(scenarios, key=lambda f : f[0]))

    def get_features(self):
        
        features = []
        for root, subFolders, files in os.walk(FEATURES_FOLDER):
          for file in files:
            features.append( self.parse_feature_file(os.path.join(root,file)) )

        return sorted(features,key=lambda f : f[0])

    def get_features_html(self):<commit_msg>Added proper file handling to cukerunner.<commit_after>#!/usr/bin/python

from __future__ import with_statement
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import subprocess

import os, cgi

FEATURES_FOLDER = "src/features"

SCENARIO_TEMPLATE = """
<li>
  %(name)s <input type="submit" name="action:%(feature)s:%(lineno)d" value="Run" />
</li>
"""

FEATURE_TEMPLATE = """
<li>
  <h3>%(name)s <input type="submit" name="action:%(feature)s" value="Run" /></h3>
  <ul class="scenarios">
    %(scenarios)s
  </ul>
</li>
"""

PAGE_TEMPLATE = """
<!DOCTYPE html>
<html>
  <head>
    <title>Cucumber test runner</title>
    <style>
      body {
        color: #333;
        font-size: 90%%;
        font-family: sans-serif;
      }

      ul {
        list-style:none;
        padding-left:5px;
        font-size:10px;
        line-height:26px;
      }

      ul li {
        display:block;
        height:26px;
        border-top:1px solid #eee;
        clear:both;
      }

      ul.scenarios li:nth-child(2n+1) {
        background:#eeffff;
      }
    
      ul li input {
        float:right;
      }

      #features > li {
        height:50px; 
      }

      #feature-container {
        width:50%%;
        float:left;
      }

      #output-container {
        width:45%%;
        float:left;
        margin-left:4%%;
      }
      #output-container textarea {
        height: 400px;
        width:100%%;
      } 
    </style>
  </head>
  <body>
    <div id="feature-container">
      <h3>Features:</h3>
      <form action="" method="POST">
        <p><input type="checkbox" name="external-server" %(external_checkbox)s /> run with external server. <input type="submit" name="action:%(features_folder)s" value="Run all" style="float:right;"/></p>
        <ul id="features">
          %(features)s
        </ul>
      </form>
    </div>
    <div id="output-container">
      <h3>Output:</h3>
      <textarea>%(console_output)s</textarea>
    </div>
  </body>
</html>
"""

class Handler(BaseHTTPRequestHandler):

    def parse_feature_file(self, path):
      
      feature_name = path
      scenarios = []

      with open(path) as f:
        line = f.readline()
        lineno = 1
        while (line != ""):
          
          if line.strip().startswith("Feature:"):
            feature_name = line.strip()[9:].strip()

          if line.strip().startswith("Scenario:"):
            scenarios.append( (line.strip()[9:].strip(), lineno) )

          lineno += 1
          line = f.readline()

      return (feature_name, path, sorted(scenarios, key=lambda f : f[0]))

    def get_features(self):
        
        features = []
        for root, subFolders, files in os.walk(FEATURES_FOLDER):
          for file in files:
            features.append( self.parse_feature_file(os.path.join(root,file)) )

        return sorted(features,key=lambda f : f[0])

    def get_features_html(self):
{'fraction_non_alphanumeric': 0.15697572900296838, 'fraction_numerical': 0.013968919154880391, 'mean_word_length': 2.2071668533034714, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5919630', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1924, 'n_words': 366}