-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import print_function | ||
from universal.compiler.language.python import Python | ||
|
||
try: | ||
import unittest | ||
import unittest.mock | ||
from unittest.mock import patch | ||
from unittest.mock import call | ||
except ImportError as e: | ||
import mock | ||
from mock import patch | ||
from mock import call | ||
|
||
|
||
class TestGpp(unittest.TestCase): | ||
def setUp(self): | ||
self.filename_py = 'foobar.py' | ||
self.compiler = Python(self.filename_py) | ||
|
||
@patch('universal.compiler.language.python.perform_system_command') | ||
def test_compile(self, mock_sys_cmd): | ||
self.compiler.compile() | ||
self.assertFalse(mock_sys_cmd.called) | ||
|
||
|
||
@patch('os.path.exists') | ||
@patch('universal.compiler.language.python.perform_system_command') | ||
def test_run_output_when_no_input_file_available(self, mock_sys_cmd, mock_path_exists): | ||
mock_path_exists.return_value = False | ||
|
||
self.compiler.run() | ||
|
||
mock_sys_cmd.assert_called_once_with(AnyStringContaining('python')) | ||
|
||
@patch('os.path.exists') | ||
@patch('universal.compiler.language.python.perform_system_command') | ||
def test_run_output_when_input_file_available(self, mock_sys_cmd, mock_path_exists): | ||
mock_path_exists.return_value = True | ||
|
||
self.compiler.run() | ||
|
||
mock_sys_cmd.assert_called_once_with(AnyStringContaining('foobar.input')) | ||
|
||
|
||
class AnyStringContaining(str): | ||
def __eq__(self, other): | ||
return self in other | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__author__ = 'shubham' | ||
from .gcc import Gcc | ||
from .gpp import Gpp | ||
from .python import Python | ||
from .language import Language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import print_function | ||
import os | ||
from .language import Language | ||
from universal.config import EXECUTABLE_PYTHON | ||
from universal.util import perform_system_command, get_file_tuple | ||
|
||
|
||
class Python(Language): | ||
@staticmethod | ||
def extension(): | ||
return 'py' | ||
|
||
def __init__(self, filename): | ||
""" :param filename: file to use | ||
""" | ||
self.filename = filename | ||
|
||
def compile(self): | ||
""" :return: 0 if compilation successful | ||
""" | ||
return 0 | ||
|
||
def run(self): | ||
command_run = get_command_to_run(self.filename) | ||
return perform_system_command(command_run) | ||
|
||
|
||
def get_command_to_run(filename): | ||
(directory, name, extension) = get_file_tuple(filename) | ||
|
||
command_run = EXECUTABLE_PYTHON + " " + filename | ||
test_file = directory + "/" + name + ".input" | ||
if os.path.exists(test_file): | ||
command_run += " < " + test_file | ||
return command_run |