Skip to content

Commit 1e1c8db

Browse files
authored
Merge pull request #1 from RumbleDB/test-workflow
Workflow for pytest
2 parents d842061 + d812d57 commit 1e1c8db

5 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python 3.11
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.11"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install flake8 pytest
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
- name: Lint with flake8
32+
run: |
33+
# stop the build if there are Python syntax errors or undefined names
34+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
- name: Test with pytest
38+
run: |
39+
pytest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,6 @@ cython_debug/
205205
marimo/_static/
206206
marimo/_lsp/
207207
__marimo__/
208+
209+
# Emacs
210+
*~

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ Repository = "https://github.com/RumbleDB/python-jsoniq.git"
3737

3838
[tool.black]
3939
line-length = 88
40+
41+
[tool.pytest.ini_options]
42+
pythonpath = [
43+
"src"
44+
]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyspark==4.0.0

tests/test_test1.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from jsoniq import RumbleSession
2+
from unittest import TestCase
3+
import json
4+
class TryTesting(TestCase):
5+
def test1(self):
6+
# The syntax to start a session is similar to that of Spark.
7+
# A RumbleSession is a SparkSession that additionally knows about RumbleDB.
8+
# All attributes and methods of SparkSession are also available on RumbleSession.
9+
rumble = RumbleSession.builder.appName("PyRumbleExample").getOrCreate();
10+
# A more complex, standalone query
11+
12+
seq = rumble.jsoniq("""
13+
let $stores :=
14+
[
15+
{ "store number" : 1, "state" : "MA" },
16+
{ "store number" : 2, "state" : "MA" },
17+
{ "store number" : 3, "state" : "CA" },
18+
{ "store number" : 4, "state" : "CA" }
19+
]
20+
let $sales := [
21+
{ "product" : "broiler", "store number" : 1, "quantity" : 20 },
22+
{ "product" : "toaster", "store number" : 2, "quantity" : 100 },
23+
{ "product" : "toaster", "store number" : 2, "quantity" : 50 },
24+
{ "product" : "toaster", "store number" : 3, "quantity" : 50 },
25+
{ "product" : "blender", "store number" : 3, "quantity" : 100 },
26+
{ "product" : "blender", "store number" : 3, "quantity" : 150 },
27+
{ "product" : "socks", "store number" : 1, "quantity" : 500 },
28+
{ "product" : "socks", "store number" : 2, "quantity" : 10 },
29+
{ "product" : "shirt", "store number" : 3, "quantity" : 10 }
30+
]
31+
let $join :=
32+
for $store in $stores[], $sale in $sales[]
33+
where $store."store number" = $sale."store number"
34+
return {
35+
"nb" : $store."store number",
36+
"state" : $store.state,
37+
"sold" : $sale.product
38+
}
39+
return [$join]
40+
""");
41+
42+
expected = [[{'nb': 1, 'state': 'MA', 'sold': 'broiler'}, {'nb': 1, 'state': 'MA', 'sold': 'socks'}, {'nb': 2, 'state': 'MA', 'sold': 'toaster'}, {'nb': 2, 'state': 'MA', 'sold': 'toaster'}, {'nb': 2, 'state': 'MA', 'sold': 'socks'}, {'nb': 3, 'state': 'CA', 'sold': 'toaster'}, {'nb': 3, 'state': 'CA', 'sold': 'blender'}, {'nb': 3, 'state': 'CA', 'sold': 'blender'}, {'nb': 3, 'state': 'CA', 'sold': 'shirt'}]]
43+
44+
self.assertTrue(json.dumps(seq.json()) == json.dumps(expected))

0 commit comments

Comments
 (0)