diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..e364045 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.gitignore b/.gitignore index b7faf40..5a019f7 100644 --- a/.gitignore +++ b/.gitignore @@ -205,3 +205,6 @@ cython_debug/ marimo/_static/ marimo/_lsp/ __marimo__/ + +# Emacs +*~ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bae735f..ddc1312 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,3 +37,8 @@ Repository = "https://github.com/RumbleDB/python-jsoniq.git" [tool.black] line-length = 88 + +[tool.pytest.ini_options] +pythonpath = [ + "src" +] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ea9b258 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyspark==4.0.0 diff --git a/tests/test_test1.py b/tests/test_test1.py new file mode 100644 index 0000000..966cf57 --- /dev/null +++ b/tests/test_test1.py @@ -0,0 +1,44 @@ +from jsoniq import RumbleSession +from unittest import TestCase +import json +class TryTesting(TestCase): + def test1(self): + # The syntax to start a session is similar to that of Spark. + # A RumbleSession is a SparkSession that additionally knows about RumbleDB. + # All attributes and methods of SparkSession are also available on RumbleSession. + rumble = RumbleSession.builder.appName("PyRumbleExample").getOrCreate(); + # A more complex, standalone query + + seq = rumble.jsoniq(""" + let $stores := + [ + { "store number" : 1, "state" : "MA" }, + { "store number" : 2, "state" : "MA" }, + { "store number" : 3, "state" : "CA" }, + { "store number" : 4, "state" : "CA" } + ] + let $sales := [ + { "product" : "broiler", "store number" : 1, "quantity" : 20 }, + { "product" : "toaster", "store number" : 2, "quantity" : 100 }, + { "product" : "toaster", "store number" : 2, "quantity" : 50 }, + { "product" : "toaster", "store number" : 3, "quantity" : 50 }, + { "product" : "blender", "store number" : 3, "quantity" : 100 }, + { "product" : "blender", "store number" : 3, "quantity" : 150 }, + { "product" : "socks", "store number" : 1, "quantity" : 500 }, + { "product" : "socks", "store number" : 2, "quantity" : 10 }, + { "product" : "shirt", "store number" : 3, "quantity" : 10 } + ] + let $join := + for $store in $stores[], $sale in $sales[] + where $store."store number" = $sale."store number" + return { + "nb" : $store."store number", + "state" : $store.state, + "sold" : $sale.product + } + return [$join] + """); + + 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'}]] + + self.assertTrue(json.dumps(seq.json()) == json.dumps(expected))