Skip to content

Commit

Permalink
changes in test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubh942 committed Jun 21, 2024
1 parent 7ac7ad5 commit 1b46dd9
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions gdbui_server/flask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
from flask import Flask
from flask_testing import TestCase
from unittest import mock
from main import app
import os

Expand All @@ -25,19 +26,41 @@ def tearDown(self):


def test_compile_code(self):
output_dir = os.path.join(self.temp_dir.name, '/output')
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Mock the os.makedirs to avoid creating actual directories
with mock.patch('os.makedirs') as mock_makedirs:
# Mock the post request to the compile endpoint
with mock.patch.object(self.client, 'post') as mock_post:
# Set up the mock response
mock_response = mock.Mock()
mock_response.status_code = 200
mock_response.json = {'output': 'Compilation successful', 'success': True}
mock_post.return_value = mock_response

# Define output directory
output_dir = os.path.join(self.temp_dir.name, 'output')

# Ensure the output directory exists (mocked)
if not os.path.exists(output_dir):
os.makedirs(output_dir) # This call is mocked

# Use a relative path for the compilation to avoid the colon issue
rel_output_dir = os.path.relpath(output_dir, self.temp_dir.name)
rel_output_dir = rel_output_dir.replace("\\", "/") # Ensure forward slashes

payload = {
"code": '#include <iostream>\nint main() { std::cout << "Hello, Universe!"; return 0; }',
"name": f"test_program2", # Use the relative path with forward slashes
}

response = self.client.post('/compile', data=json.dumps(payload), content_type='application/json')
print('opopop')
print(response.json['output'])
self.assertEqual(response.status_code, 200)
self.assertTrue(response.json['success'])

# Assert that os.makedirs was called with the expected directory
mock_makedirs.assert_called_with(output_dir)

payload = {
"code": '#include <iostream>\nint main() { std::cout << "Hello, Universe!"; return 0; }',
"name": f"test_program2", # Use forward slashes
}
response = self.client.post('/compile', data=json.dumps(payload), content_type='application/json')
print('opopop')
print(response.json['output'])
self.assertEqual(response.status_code, 200)
self.assertTrue(response.json['success'])

def test_gdb_command(self):
gdb_payload = {
Expand Down

0 comments on commit 1b46dd9

Please sign in to comment.