Skip to content

Commit 6a3d9a8

Browse files
committed
Merge branch 'develop' into program-persistence
2 parents d2f05b7 + b9291cd commit 6a3d9a8

File tree

7 files changed

+132
-5
lines changed

7 files changed

+132
-5
lines changed

.circleci/config.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: coderbot/python-gpac:3.5
11+
12+
working_directory: ~/repo
13+
14+
steps:
15+
- checkout
16+
17+
# Download and cache dependencies
18+
- restore_cache:
19+
keys:
20+
- v1-dependencies-{{ checksum "requirements_stub.txt" }}
21+
# fallback to using the latest cache if no exact match is found
22+
- v1-dependencies-
23+
24+
- run:
25+
name: install dependencies
26+
command: |
27+
python3 -m venv venv
28+
. venv/bin/activate
29+
pip install -r requirements_stub.txt
30+
31+
- save_cache:
32+
paths:
33+
- ./venv
34+
key: v1-dependencies-{{ checksum "requirements_stub.txt" }}
35+
36+
# run tests!
37+
- run:
38+
name: run tests
39+
command: |
40+
. venv/bin/activate
41+
export PYTHONPATH=./stub
42+
mkdir test-reports
43+
python3 -m unittest test/coderbot_test.py 2>&1 | tee test-reports/test_report.txt
44+
#python3 -m unittest test/cnn_test.py 2>&1 | tee test-reports/test_report.txt
45+
python3 -m unittest test/camera_test.py 2>&1 | tee test-reports/test_report.txt
46+
echo "test complete"
47+
- store_artifacts:
48+
path: test-reports/
49+
destination: tr1
50+
51+
- store_test_results:
52+
path: test-reports/
53+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ Once started, the backend will expose a number of endpoints:
4242
- Legacy JQuery web application: [localhost:5000/old](http://localhost:5000/old);
4343
- API v2: [localhost:5000/v2](http://localhost:5000/v2);
4444
- New Vue web application: [localhost:5000/](http://localhost:5000/) (assuming a [vue-app](https://github.com/coderbotorg/vue-app) build is placed in the `dist/` folder);
45+
- Documentation: [localhost:5000/docs](http://localhost:5000/docs) assuming a [docs](https://github.com/coderbotorg/docs) build is placed in the `cb_docs/` folder);
4546
- Swagger UI dynamic documentation of the API v2: [localhost:5000/v2/ui/index.html](http://localhost:5000/v2/ui/index.html) (once you cloned the [swagger-ui](https://github.com/coderbotorg/swagger-ui) repository inside the backend folder).
4647

main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,21 @@
6868
def serve_vue_app(filename):
6969
"""
7070
Serve (a build of) the new Vue application
71-
"dist" is the output of `npm run build` from the 'vue-app 'repository
71+
"dist" is the output of `npm run build` from the 'vue-app' repository
7272
"""
7373
return send_from_directory('dist', filename)
7474

75+
@app.route('/docs/<path:filename')
76+
def serve_docs_app(filename):
77+
"""
78+
Serve (a build of) the documentation
79+
'cb_docs' is the output of `npx vuepress build pages/`
80+
from the 'docs' repository
81+
"""
82+
return send_from_directory('cb_docs', filename)
83+
7584
@app.route('/')
7685
def redirect_vue_app():
77-
7886
return redirect('/vue/index.html', code=302)
7987

8088
## Legacy API and web application

requirements_stub.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jsonschema==2.6.0
2323
Markdown==2.6.11
2424
MarkupSafe==1.0
2525
numpy==1.14.3
26-
opencv-contrib-python
26+
opencv-contrib-python==3.4.3.18
2727
pigpio==1.40.post1
2828
Pillow==5.1.0
2929
protobuf==3.6.1

stub/pigpio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from test.pigpio_mock import PIGPIOMock
1+
#from test.pigpio_mock import PIGPIOMock
22

3-
pi = PIGPIOMock
43
INPUT=1
54
OUTPUT=2
65
RISING_EDGE=1
76
EITHER_EDGE=2
7+
8+
class pi:
9+
def __init__(self, host="localhost", port=8888):
10+
pass

test/audio_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
import os
3+
import test.pyaudio_mock
4+
import pyaudio
5+
import audio
6+
7+
FILENAME = "test.wav"
8+
9+
class AudioTest(unittest.TestCase):
10+
def setUp(self):
11+
pyaudio.PyAudio = test.pyaudio_mock.PyAudioMock
12+
self.audio = audio.Audio.get_instance()
13+
14+
def tearDown(self):
15+
pass
16+
17+
def test_say(self):
18+
self.audio.say("this is a test")
19+
self.assertTrue(True)
20+
21+
def test_record_to_file(self):
22+
self.audio.record_to_file(FILENAME, 3)
23+
self.assertTrue(os.path.isfile(os.path.join(audio.SOUNDDIR, FILENAME)))
24+
25+
def test_play(self):
26+
self.audio.play(FILENAME)
27+
self.assertTrue(True)
28+
29+
def test_hear(self):
30+
self.assertTrue(True)
31+

test/pyaudio_mock.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest.mock
2+
import time
3+
import io
4+
import logging
5+
import numpy
6+
7+
logger = logging.getLogger()
8+
9+
class PyAudioMock(object):
10+
"""Implements PyAudio mock class
11+
PyAudio is the library used to access the integrated audio output and external audio source (microphone)
12+
"""
13+
14+
def __init__(self):
15+
pass
16+
17+
def open(self, format, channels, rate, frames_per_buffer, stream_callback):
18+
return self
19+
20+
def stop_stream(self):
21+
pass
22+
23+
def close(self):
24+
pass
25+
26+
def terminate(self):
27+
pass
28+
29+
def get_sample_size(format):
30+
return format * 16
31+

0 commit comments

Comments
 (0)