def upload(): file = request.files['file'] filename = '{}.pdf'.format( file.filename) if "." not in file.filename else file.filename file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(file_path) try: output, raw_output = process_file(file_path) response = app.response_class(response=json.dumps({ 'data': output, 'raw_output': raw_output }), status=StatusCode.HTTP_200_OK.value, mimetype='application/json') os.remove(file_path) return response except Exception as e: os.remove(file_path) return app.response_class(response=json.dumps({'error': str(e)}), status=StatusCode.HTTP_400_BAD_REQUEST.value, mimetype='application/json')
def test_decompressing(tmpdir): inpath = os.path.join(THIS_FILE, 'data/in/files/decompress_this.snappy') outpath = tmpdir.mkdir('out').join('decompress_this') out = process_file(inpath, outpath.strpath) with open(out) as f: decompressed = f.read() expected = """what,who Hello,World""" assert decompressed == expected
def upload_file(): # DISCLAIMER: uploading a file in a local server setting does not really make sense. # What this does now is that it copies the provided file to the output directory -- only really, REALLY slowly. # This should probably change. # No time for that within this hackathon, though. Oops, sorry! :) uploaded_file = request.files['file'] if uploaded_file.filename != '': filepath = os.path.join(app.config['UPLOAD_PATH'], uploaded_file.filename) out_dir = app.config['UPLOAD_PATH'] uploaded_file.save(filepath) out_filepaths = process_file(filepath, out_dir) visualisations = [] for f in out_filepaths: print(f) with open(f, 'r') as out_file: visualisations.append(out_file.read()) print() return render_template('index.html', visualizations=visualisations, audio_url=f'/uploads/{uploaded_file.filename}') else: return redirect(url_for('index'))
def main(): for index, test in enumerate(TESTS): print(f"\n\nStarting Test {index + 1}...") program, result, timeout = test.values() assert run_test(process_file(program), result, timeout)
def test_read_records_malformed(self): # Call file = process_file('./test/malformed-file.log') # Assert self.assertEqual(len(file.records), 19)
def test_read_empty_file(self): # Call file = process_file('./test/empty-file.log') # Assert self.assertEqual(len(file.records), 0)
def test_read_records(self): # Call file = process_file('./test/test-file.log') # Assert self.assertEqual(len(file.records), 23)