Exemplo n.º 1
0
def code(data):
    file = make_file(data)
    if 'fix' in data:
        res = lint_code(file, data, True)
        res['tab'] = data['index']
        socketio.emit('fixed', res, request.sid)
    else:
        res = lint_code(file, data)
        res['tab'] = data['index']
        socketio.emit('output', res, request.sid)
    subprocess.run(['rm', '-r', f'./userfiles/{res["filename"]}'])
    subprocess.run(['rm', '-r', f'./userfiles/.{res["filename"]}'])
Exemplo n.º 2
0
    def test_lint_code_py(self):
        with patch('lint.pylint') as mock_pylint:
            mock_pylint.return_value = None
            res = lint.lint_code({
                'linter': 'pylint',
                'code': 'def func():\n  print("Hello")',
                'uuid': 'testfile',
                'filename': 'testfile'
            }, {'styleguide': 'airbnb'})
            here = os.path.dirname(os.path.abspath(__file__))
            here = re.sub(r'tests\/.*', "", here).replace("tests", "")
            subdir = "userfiles"
            filepath = os.path.join(here, subdir, "testfile.py")
            file = open(filepath, "r")
            self.assertEqual(file.read(), 'def func():\n  print("Hello")')

            flask_test_client = app.test_client()
            socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
            with patch('app.lint_code') as mock_method:
                mock_method.return_value = {
                    'filename': 'testfile.py'
                }
                socketio_test_client.emit('lint', {'linter': 'pylint',
                'code': 'def func():\n  print("Hello")',
                'uuid': 'testfile','index': '0'})
                res = socketio_test_client.get_received()[1]['args'][0]['filename']
                self.assertEqual(res, 'testfile.py')
Exemplo n.º 3
0
    def test_lint_code_js(self):
        with patch('lint.eslint') as mock_eslint:
            mock_eslint.return_value = None
            res = lint.lint_code({
                'linter': 'eslint',
                'code': 'function test(){\nconsole.log("Hello")\n}',
                'uuid': 'testfile'
            })
            here = os.path.dirname(os.path.abspath(__file__))
            here = re.sub(r'tests\/.*', "", here).replace("tests", "")
            subdir = "userfiles"
            filepath = os.path.join(here, subdir, "testfile.js")
            file = open(filepath, "r")
            self.assertEqual(file.read(),
                             'function test(){\nconsole.log("Hello")\n}')

            flask_test_client = app.test_client()
            socketio_test_client = socketio.test_client(
                app, flask_test_client=flask_test_client)
            with patch('app.lint_code') as mock_method:
                mock_method.return_value = {'filename': 'testfile.js'}
                socketio_test_client.emit('lint', {})
                res = socketio_test_client.get_received(
                )[1]['args'][0]['filename']
                self.assertEqual(res, 'testfile.js')
Exemplo n.º 4
0
def code(data):
    res = lint_code(data)
    socketio.emit('output', res, request.sid)
    subprocess.run(['rm', '-r', f'./userfiles/{res["filename"]}'])