help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
code-assistant-bot
/
utils
/
__pycache__
RSK World
code-assistant-bot
Code Assistant Bot - Python + Flask + OpenAI API + Code Generation + Debugging + Code Analysis + GitHub Integration
__pycache__
  • code_analyzer.cpython-313.pyc17.6 KB
  • code_comparator.cpython-313.pyc6.5 KB
  • code_documenter.cpython-313.pyc14 KB
  • code_formatter.cpython-313.pyc9.9 KB
  • code_reviewer.cpython-313.pyc10.5 KB
  • github_integration.cpython-313.pyc14.2 KB
  • syntax_checker.cpython-313.pyc21.6 KB
app.cpython-313.pycstyle.csscode_tester.py
app.cpython-313.pyc

This file cannot be displayed in the browser.

Download File
static/css/style.css
Raw Download
Find: Go to:
/*
Code Assistant Bot Styles
Author: RSK World (https://rskworld.in)
Founder: Molla Samser
Designer & Tester: Rima Khatun
Contact: help@rskworld.in, +91 93305 39277
Year: 2026
*/

/* Global Styles */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --rsk-blue: #0066cc;
    --rsk-green: #28a745;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
    font-weight: 600;
}

header .text-muted {
    font-size: 0.9rem;
}

/* Main Content */
main {
    flex: 1;
}

/* Card Styles */
.card {
    border: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: transform 0.2s ease-in-out;
}

.card:hover {
    transform: translateY(-2px);
}

.card-header {
    font-weight: 600;
    border-bottom: 2px solid rgba(0,0,0,0.1);
}

/* Form Controls */
.form-control {
    border-radius: 0.375rem;
    border: 1px solid #ced4da;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.form-select {
    border-radius: 0.375rem;
    border: 1px solid #ced4da;
}

/* Button Styles */
.btn {
    border-radius: 0.375rem;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

.btn-success {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.btn-info {
    background-color: var(--info-color);
    border-color: var(--info-color);
}

/* Code Input and Output Areas */
.font-monospace {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
}

#codeInput {
    resize: vertical;
    min-height: 200px;
}

#outputContent {
    max-height: 500px;
    overflow-y: auto;
}

#outputCode {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Loading Spinner */
.spinner-border {
    width: 3rem;
    height: 3rem;
}

/* GitHub Results */
.github-result-card {
    border: 1px solid #e1e4e8;
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: white;
    transition: all 0.2s ease-in-out;
}

.github-result-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.github-result-card h6 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.github-result-card .badge {
    font-size: 0.75rem;
}

.github-stats {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.github-stats small {
    color: var(--secondary-color);
}

/* Welcome Message */
#welcomeMessage {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 0.5rem;
    margin: 1rem 0;
}

#welcomeMessage h5 {
    color: white;
}

#welcomeMessage .text-muted {
    color: rgba(255, 255, 255, 0.8) !important;
}

/* Features Section */
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.feature-card {
    text-align: center;
    padding: 2rem 1rem;
    border-radius: 0.5rem;
    background: white;
    transition: all 0.3s ease-in-out;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.feature-card i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.8;
    transition: all 0.3s ease-in-out;
}

.feature-card:hover i {
    opacity: 1;
    transform: scale(1.1);
}

/* Footer */
footer {
    margin-top: auto;
    background: linear-gradient(135deg, #343a40 0%, #212529 100%);
}

footer h6 {
    color: white;
    font-weight: 600;
}

footer a {
    text-decoration: none;
    transition: color 0.2s ease-in-out;
}

footer a:hover {
    color: var(--primary-color);
}

/* Toast Notifications */
.toast {
    background-color: white;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast-header {
    background-color: var(--light-color);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

/* Syntax Highlighting Overrides */
pre[class*="language-"] {
    margin: 0;
    padding: 1rem;
    background-color: #2d2d2d;
    border-radius: 0.375rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

code[class*="language-"] {
    color: #f8f8f2;
    text-shadow: 0 1px rgba(0,0,0,0.3);
    font-family: 'Courier New', Courier, monospace;
}

/* Character Counter */
.form-text {
    font-size: 0.875rem;
    color: var(--secondary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .github-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    header .text-md-end {
        text-align: left !important;
        margin-top: 1rem;
    }
    
    footer .text-md-end {
        text-align: left !important;
        margin-top: 1rem;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

.fade-out {
    animation: fadeOut 0.5s ease-out;
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Code Line Numbers */
.line-numbers .line-numbers-rows {
    border-right: 1px solid #999;
}

.line-numbers-rows > span:before {
    color: #999;
}

/* Error Highlighting */
.error-highlight {
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 4px solid var(--danger-color);
    padding-left: 0.5rem;
}

/* Success Highlighting */
.success-highlight {
    background-color: rgba(40, 167, 69, 0.1);
    border-left: 4px solid var(--success-color);
    padding-left: 0.5rem;
}

/* Warning Highlighting */
.warning-highlight {
    background-color: rgba(255, 193, 7, 0.1);
    border-left: 4px solid var(--warning-color);
    padding-left: 0.5rem;
}

/* Loading States */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 0.375rem;
}

/* Copy Button Animation */
.copy-success {
    animation: copySuccess 1s ease-in-out;
}

@keyframes copySuccess {
    0% { background-color: var(--success-color); }
    100% { background-color: var(--primary-color); }
}

/* GitHub Language Colors */
.language-python { color: #3572A5; }
.language-javascript { color: #f1e05a; }
.language-typescript { color: #2b7489; }
.language-java { color: #b07219; }
.language-cpp { color: #f34b7d; }
.language-c { color: #555555; }
.language-csharp { color: #239120; }
.language-php { color: #4F5D95; }
.language-ruby { color: #701516; }
.language-go { color: #00ADD8; }
.language-rust { color: #dea584; }
.language-html { color: #e34c26; }
.language-css { color: #563d7c; }

/* New Feature Colors */
.text-purple { color: #6f42c1; }

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus Styles */
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    header,
    footer,
    .btn,
    #githubSearchInput,
    #githubSearchBtn,
    #clearGithubBtn {
        display: none !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    body {
        background-color: white;
    }
}
477 lines•9 KB
css
utils/code_tester.py
Raw Download
Find: Go to:
"""
Code Tester Utility for Code Assistant Bot
Author: RSK World (https://rskworld.in)
Founder: Molla Samser
Designer & Tester: Rima Khatun
Contact: help@rskworld.in, +91 93305 39277
Year: 2026
"""

import subprocess
import tempfile
import os
import re
import json
import time
from typing import Dict, List, Any, Optional, Tuple

class CodeTester:
    """
    Advanced code testing and validation utility
    """
    
    def __init__(self):
        self.supported_languages = {
            'python': {'extension': 'py', 'command': 'python'},
            'javascript': {'extension': 'js', 'command': 'node'},
            'java': {'extension': 'java', 'command': 'javac && java'},
            'cpp': {'extension': 'cpp', 'command': 'g++ -o temp && ./temp'},
            'c': {'extension': 'c', 'command': 'gcc -o temp && ./temp'},
            'csharp': {'extension': 'cs', 'command': 'dotnet run'},
            'php': {'extension': 'php', 'command': 'php'},
            'ruby': {'extension': 'rb', 'command': 'ruby'},
            'go': {'extension': 'go', 'command': 'go run'},
            'rust': {'extension': 'rs', 'command': 'cargo run'},
            'typescript': {'extension': 'ts', 'command': 'ts-node'}
        }
        
        self.test_templates = {
            'python': {
                'unit_test': '''
import unittest
import sys
import io

{user_code}

class TestGeneratedCode(unittest.TestCase):
    {test_methods}

if __name__ == '__main__':
    unittest.main()
''',
                'integration_test': '''
{user_code}

# Integration tests
{integration_code}
'''
            },
            'javascript': {
                'unit_test': '''
const assert = require('assert');

{user_code}

// Unit tests
{test_methods}
''',
                'integration_test': '''
{user_code}

// Integration tests
{integration_code}
'''
            }
        }
    
    def test_code(self, code: str, language: str, test_type: str = 'syntax', test_cases: List[Dict] = None) -> Dict[str, Any]:
        """
        Test code with various test types
        """
        try:
            if language not in self.supported_languages:
                return {
                    'success': False,
                    'error': f'Language {language} not supported for testing',
                    'results': {}
                }
            
            if test_type == 'syntax':
                return self._test_syntax(code, language)
            elif test_type == 'unit':
                return self._run_unit_tests(code, language, test_cases)
            elif test_type == 'integration':
                return self._run_integration_tests(code, language, test_cases)
            elif test_type == 'performance':
                return self._test_performance(code, language)
            elif test_type == 'security':
                return self._test_security(code, language)
            else:
                return {
                    'success': False,
                    'error': f'Test type {test_type} not supported',
                    'results': {}
                }
                
        except Exception as e:
            return {
                'success': False,
                'error': f'Testing failed: {str(e)}',
                'results': {}
            }
    
    def _test_syntax(self, code: str, language: str) -> Dict[str, Any]:
        """Test code syntax"""
        try:
            with tempfile.NamedTemporaryFile(mode='w', suffix=f'.{self.supported_languages[language]["extension"]}', delete=False) as f:
                f.write(code)
                temp_file = f.name
            
            try:
                if language == 'python':
                    result = subprocess.run(['python', '-m', 'py_compile', temp_file], 
                                          capture_output=True, text=True, timeout=10)
                elif language == 'javascript':
                    result = subprocess.run(['node', '-c', temp_file], 
                                          capture_output=True, text=True, timeout=10)
                elif language == 'java':
                    result = subprocess.run(['javac', temp_file], 
                                          capture_output=True, text=True, timeout=10)
                else:
                    # For other languages, try basic compilation
                    command = self.supported_languages[language]['command'].split()[0]
                    result = subprocess.run([command, '--check', temp_file] if language in ['python', 'javascript'] else [command, temp_file], 
                                          capture_output=True, text=True, timeout=10)
                
                return {
                    'success': result.returncode == 0,
                    'syntax_valid': result.returncode == 0,
                    'error': result.stderr if result.returncode != 0 else None,
                    'output': result.stdout,
                    'language': language
                }
                
            finally:
                os.unlink(temp_file)
                
        except subprocess.TimeoutExpired:
            return {
                'success': False,
                'error': 'Syntax check timed out',
                'syntax_valid': False,
                'language': language
            }
        except Exception as e:
            return {
                'success': False,
                'error': f'Syntax test failed: {str(e)}',
                'syntax_valid': False,
                'language': language
            }
    
    def _run_unit_tests(self, code: str, language: str, test_cases: List[Dict] = None) -> Dict[str, Any]:
        """Run unit tests on the code"""
        try:
            if not test_cases:
                # Generate basic test cases
                test_cases = self._generate_test_cases(code, language)
            
            if language == 'python':
                return self._run_python_unit_tests(code, test_cases)
            elif language == 'javascript':
                return self._run_javascript_unit_tests(code, test_cases)
            else:
                return {
                    'success': False,
                    'error': f'Unit testing not fully supported for {language}',
                    'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
                }
                
        except Exception as e:
            return {
                'success': False,
                'error': f'Unit testing failed: {str(e)}',
                'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
            }
    
    def _run_python_unit_tests(self, code: str, test_cases: List[Dict]) -> Dict[str, Any]:
        """Run Python unit tests"""
        try:
            # Extract functions from code
            functions = re.findall(r'def\s+(\w+)\s*\(', code)
            
            if not functions:
                return {
                    'success': False,
                    'error': 'No functions found to test',
                    'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
                }
            
            # Generate test methods
            test_methods = ''
            for i, test_case in enumerate(test_cases):
                test_methods += f'''
    def test_{i+1}(self):
        """Test case: {test_case.get('description', 'Test case ' + str(i+1))}"""
        try:
            {test_case.get('test_code', 'pass')}
            self.assertTrue(True)  # Test passed
        except Exception as e:
            self.fail(f"Test failed: {{str(e)}}")
'''
            
            # Create test file
            test_template = self.test_templates['python']['unit_test']
            full_test_code = test_template.format(
                user_code=code,
                test_methods=test_methods
            )
            
            with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
                f.write(full_test_code)
                temp_file = f.name
            
            try:
                result = subprocess.run(['python', temp_file], 
                                      capture_output=True, text=True, timeout=30)
                
                # Parse test results
                output = result.stdout + result.stderr
                tests_run = len(re.findall(r'\.\.\.', output))
                failed_tests = len(re.findall(r'FAIL:', output))
                error_tests = len(re.findall(r'ERROR:', output))
                passed_tests = tests_run - failed_tests - error_tests
                
                return {
                    'success': result.returncode == 0,
                    'results': {
                        'tests_run': tests_run,
                        'passed': passed_tests,
                        'failed': failed_tests + error_tests,
                        'output': output,
                        'details': self._parse_test_output(output)
                    }
                }
                
            finally:
                os.unlink(temp_file)
                
        except Exception as e:
            return {
                'success': False,
                'error': f'Python unit testing failed: {str(e)}',
                'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
            }
    
    def _run_javascript_unit_tests(self, code: str, test_cases: List[Dict]) -> Dict[str, Any]:
        """Run JavaScript unit tests"""
        try:
            # Simple JavaScript testing
            test_code = code + '\n\n// Tests\n'
            
            passed = 0
            failed = 0
            test_results = []
            
            for i, test_case in enumerate(test_cases):
                test_code += f'''
try {{
    {test_case.get('test_code', 'console.log("Test passed")')}
    console.log('TEST_PASSED_{i}');
}} catch (e) {{
    console.log('TEST_FAILED_' + i + ':' + e.message);
}}
'''
            
            with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f:
                f.write(test_code)
                temp_file = f.name
            
            try:
                result = subprocess.run(['node', temp_file], 
                                      capture_output=True, text=True, timeout=30)
                
                output = result.stdout
                passed = len(re.findall(r'TEST_PASSED_\d+', output))
                failed_tests = re.findall(r'TEST_FAILED_(\d+):(.+)', output)
                failed = len(failed_tests)
                
                for test_id, error_msg in failed_tests:
                    test_results.append({
                        'test_id': int(test_id),
                        'status': 'failed',
                        'error': error_msg
                    })
                
                for i in range(passed):
                    test_results.append({
                        'test_id': i,
                        'status': 'passed',
                        'error': None
                    })
                
                return {
                    'success': result.returncode == 0,
                    'results': {
                        'tests_run': passed + failed,
                        'passed': passed,
                        'failed': failed,
                        'output': output,
                        'details': test_results
                    }
                }
                
            finally:
                os.unlink(temp_file)
                
        except Exception as e:
            return {
                'success': False,
                'error': f'JavaScript unit testing failed: {str(e)}',
                'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
            }
    
    def _run_integration_tests(self, code: str, language: str, test_cases: List[Dict] = None) -> Dict[str, Any]:
        """Run integration tests"""
        try:
            # For now, return basic integration testing
            return {
                'success': True,
                'results': {
                    'tests_run': 1,
                    'passed': 1,
                    'failed': 0,
                    'message': 'Integration testing completed - basic validation passed'
                }
            }
        except Exception as e:
            return {
                'success': False,
                'error': f'Integration testing failed: {str(e)}',
                'results': {'tests_run': 0, 'passed': 0, 'failed': 0}
            }
    
    def _test_performance(self, code: str, language: str) -> Dict[str, Any]:
        """Test code performance"""
        try:
            with tempfile.NamedTemporaryFile(mode='w', suffix=f'.{self.supported_languages[language]["extension"]}', delete=False) as f:
                # Add performance measurement
                if language == 'python':
                    perf_code = f'''
import time
import sys

start_time = time.time()

{code}

end_time = time.time()
execution_time = end_time - start_time
print(f"EXECUTION_TIME:{{execution_time}}")
print(f"MEMORY_USAGE:{{sys.getsizeof(locals())}}")
'''
                elif language == 'javascript':
                    perf_code = f'''
const start = Date.now();

{code}

const end = Date.now();
console.log(`EXECUTION_TIME:${end - start}`);
'''
                else:
                    perf_code = code
                
                f.write(perf_code)
                temp_file = f.name
            
            try:
                command = self.supported_languages[language]['command'].split()[0]
                result = subprocess.run([command, temp_file], 
                                      capture_output=True, text=True, timeout=30)
                
                output = result.stdout
                execution_time = None
                
                # Extract execution time
                time_match = re.search(r'EXECUTION_TIME:(\d+\.?\d*)', output)
                if time_match:
                    execution_time = float(time_match.group(1))
                
                return {
                    'success': True,
                    'results': {
                        'execution_time': execution_time,
                        'output': output,
                        'performance_score': self._calculate_performance_score(execution_time)
                    }
                }
                
            finally:
                os.unlink(temp_file)
                
        except Exception as e:
            return {
                'success': False,
                'error': f'Performance testing failed: {str(e)}',
                'results': {}
            }
    
    def _test_security(self, code: str, language: str) -> Dict[str, Any]:
        """Test code for security vulnerabilities"""
        try:
            security_issues = []
            
            # Check for common security vulnerabilities
            security_patterns = {
                'sql_injection': [
                    r'execute\s*\(\s*["\'][^"\']*%[^"\']*["\']',
                    r'query\s*\(\s*["\'][^"\']*%[^"\']*["\']'
                ],
                'code_injection': [
                    r'eval\s*\(',
                    r'exec\s*\(',
                    r'system\s*\('
                ],
                'hardcoded_secrets': [
                    r'password\s*=\s*["\'][^"\']+["\']',
                    r'api_key\s*=\s*["\'][^"\']+["\']',
                    r'secret\s*=\s*["\'][^"\']+["\']'
                ],
                'path_traversal': [
                    r'open\s*\([^)]*\.\.',
                    r'read\s*\([^)]*\.\.'
                ],
                'xss': [
                    r'innerHTML\s*=',
                    r'outerHTML\s*=',
                    r'document\.write\s*\('
                ]
            }
            
            for vulnerability_type, patterns in security_patterns.items():
                for pattern in patterns:
                    matches = re.finditer(pattern, code, re.IGNORECASE)
                    for match in matches:
                        line_num = code[:match.start()].count('\n') + 1
                        security_issues.append({
                            'type': vulnerability_type,
                            'severity': self._get_severity(vulnerability_type),
                            'line': line_num,
                            'description': self._get_security_description(vulnerability_type),
                            'code_snippet': code[match.start():match.end()]
                        })
            
            return {
                'success': True,
                'results': {
                    'security_issues': security_issues,
                    'security_score': self._calculate_security_score(security_issues),
                    'total_issues': len(security_issues)
                }
            }
            
        except Exception as e:
            return {
                'success': False,
                'error': f'Security testing failed: {str(e)}',
                'results': {}
            }
    
    def _generate_test_cases(self, code: str, language: str) -> List[Dict]:
        """Generate basic test cases for the code"""
        test_cases = []
        
        if language == 'python':
            functions = re.findall(r'def\s+(\w+)\s*\(', code)
            for func in functions:
                test_cases.append({
                    'description': f'Test function {func}',
                    'test_code': f'# Test {func}\nresult = {func}()\nprint("Test passed")'
                })
        
        elif language == 'javascript':
            functions = re.findall(r'function\s+(\w+)\s*\(', code)
            for func in functions:
                test_cases.append({
                    'description': f'Test function {func}',
                    'test_code': f'// Test {func}\nconst result = {func}();\nconsole.log("Test passed");'
                })
        
        return test_cases
    
    def _parse_test_output(self, output: str) -> List[Dict]:
        """Parse test output for detailed results"""
        details = []
        
        # Parse Python unittest output
        lines = output.split('\n')
        for line in lines:
            if 'FAIL:' in line or 'ERROR:' in line:
                details.append({
                    'status': 'failed',
                    'message': line.strip()
                })
            elif 'ok' in line and 'test' in line.lower():
                details.append({
                    'status': 'passed',
                    'message': line.strip()
                })
        
        return details
    
    def _calculate_performance_score(self, execution_time: float) -> str:
        """Calculate performance score based on execution time"""
        if execution_time is None:
            return 'unknown'
        elif execution_time < 0.1:
            return 'excellent'
        elif execution_time < 0.5:
            return 'good'
        elif execution_time < 2.0:
            return 'average'
        else:
            return 'poor'
    
    def _get_severity(self, vulnerability_type: str) -> str:
        """Get severity level for vulnerability type"""
        severity_map = {
            'sql_injection': 'critical',
            'code_injection': 'critical',
            'hardcoded_secrets': 'high',
            'path_traversal': 'high',
            'xss': 'medium'
        }
        return severity_map.get(vulnerability_type, 'low')
    
    def _get_security_description(self, vulnerability_type: str) -> str:
        """Get description for vulnerability type"""
        descriptions = {
            'sql_injection': 'Potential SQL injection vulnerability',
            'code_injection': 'Potential code injection vulnerability',
            'hardcoded_secrets': 'Hardcoded secret detected',
            'path_traversal': 'Potential path traversal vulnerability',
            'xss': 'Potential XSS vulnerability'
        }
        return descriptions.get(vulnerability_type, 'Security issue detected')
    
    def _calculate_security_score(self, issues: List[Dict]) -> int:
        """Calculate security score based on issues"""
        if not issues:
            return 100
        
        score = 100
        for issue in issues:
            severity = issue['severity']
            if severity == 'critical':
                score -= 30
            elif severity == 'high':
                score -= 20
            elif severity == 'medium':
                score -= 10
            elif severity == 'low':
                score -= 5
        
        return max(0, score)
567 lines•20.8 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer