From 88814afdbcb3f6e09cc8ad9434e415983c9ab39f Mon Sep 17 00:00:00 2001 From: abi01shek Date: Tue, 15 Jul 2025 10:27:05 +0200 Subject: [PATCH 1/6] Workflow for pytest --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml 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 From 18c43daf03a5a72a58500018346bf6dfd1c2e1f6 Mon Sep 17 00:00:00 2001 From: abi01shek Date: Tue, 15 Jul 2025 10:35:03 +0200 Subject: [PATCH 2/6] Create test_test0.py Testing pytest --- tests/test_test0.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/test_test0.py diff --git a/tests/test_test0.py b/tests/test_test0.py new file mode 100644 index 0000000..91a9e18 --- /dev/null +++ b/tests/test_test0.py @@ -0,0 +1,8 @@ +from unittest import TestCase + +class TryTesting(TestCase): + def test_always_passes(self): + self.assertTrue(True) + + def test_always_fails(self): + self.assertTrue(False) From d0113df376b232abb4150face38b11d87fd03a95 Mon Sep 17 00:00:00 2001 From: Abishek Date: Tue, 15 Jul 2025 11:01:52 +0200 Subject: [PATCH 3/6] Adding jsoniq simple testcase --- .gitignore | 3 +++ tests/test_test1.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/test_test1.py 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/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)) From a1647499303b3271f5d4e853a3c8b30ec77c19ac Mon Sep 17 00:00:00 2001 From: Abishek Date: Tue, 15 Jul 2025 11:04:28 +0200 Subject: [PATCH 4/6] Removed pytest testcase --- tests/test_test0.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 tests/test_test0.py diff --git a/tests/test_test0.py b/tests/test_test0.py deleted file mode 100644 index 91a9e18..0000000 --- a/tests/test_test0.py +++ /dev/null @@ -1,8 +0,0 @@ -from unittest import TestCase - -class TryTesting(TestCase): - def test_always_passes(self): - self.assertTrue(True) - - def test_always_fails(self): - self.assertTrue(False) From 560e649280948a3fd3f3a1f3cf230d36e901217c Mon Sep 17 00:00:00 2001 From: Abishek Date: Tue, 15 Jul 2025 11:14:07 +0200 Subject: [PATCH 5/6] Added path to src in toml --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) 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" +] From d812d57d38c0d16ceaa18bbde11c4d91009cc01e Mon Sep 17 00:00:00 2001 From: Abishek Date: Tue, 15 Jul 2025 11:16:51 +0200 Subject: [PATCH 6/6] Fix pyspark version requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt 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