sqlcompose 0.0.3__tar.gz → 0.0.4a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/LICENSE +1 -1
  2. {sqlcompose-0.0.3/src/sqlcompose.egg-info → sqlcompose-0.0.4a1}/PKG-INFO +7 -7
  3. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/README.md +3 -4
  4. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/pyproject.toml +7 -5
  5. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/__init__.py +3 -3
  6. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/core/app.py +6 -3
  7. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/core/compat.py +14 -2
  8. sqlcompose-0.0.4a1/src/sqlcompose/core/file_not_found_err.py +11 -0
  9. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/core/functions.py +7 -5
  10. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1/src/sqlcompose.egg-info}/PKG-INFO +7 -7
  11. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose.egg-info/SOURCES.txt +1 -0
  12. sqlcompose-0.0.4a1/tests/test_app.py +31 -0
  13. sqlcompose-0.0.4a1/tests/test_compat.py +48 -0
  14. sqlcompose-0.0.4a1/tests/test_functions.py +42 -0
  15. sqlcompose-0.0.3/tests/test_app.py +0 -29
  16. sqlcompose-0.0.3/tests/test_compat.py +0 -52
  17. sqlcompose-0.0.3/tests/test_functions.py +0 -40
  18. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/setup.cfg +0 -0
  19. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/__main__.py +0 -0
  20. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/core/circular_dependency_error.py +0 -0
  21. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/core/include.py +0 -0
  22. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose/py.typed +0 -0
  23. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose.egg-info/dependency_links.txt +0 -0
  24. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose.egg-info/entry_points.txt +0 -0
  25. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose.egg-info/requires.txt +0 -0
  26. {sqlcompose-0.0.3 → sqlcompose-0.0.4a1}/src/sqlcompose.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dagrofa
3
+ Copyright (c) 2025 Anders Madsen
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlcompose
3
- Version: 0.0.3
3
+ Version: 0.0.4a1
4
4
  Summary: Composition of linked SQL files
5
5
  Author-email: Anders Madsen <anders.madsen@alphavue.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: repository, https://github.com/apmadsen/sqlcompose
8
8
  Keywords: sql,composition,windows,linux
9
9
  Classifier: Development Status :: 5 - Production/Stable
@@ -18,11 +18,12 @@ Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
21
22
  Classifier: Programming Language :: Python
22
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
24
  Classifier: Topic :: Software Development :: Libraries
24
25
  Classifier: Typing :: Typed
25
- Requires-Python: >=3.10
26
+ Requires-Python: <3.15,>=3.10
26
27
  Description-Content-Type: text/markdown
27
28
  License-File: LICENSE
28
29
  Provides-Extra: test
@@ -32,10 +33,10 @@ Dynamic: license-file
32
33
 
33
34
  [![Test](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml)
34
35
  [![Coverage](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml)
35
- ![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)
36
+ [![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/sqlcompose/releases)
36
37
  ![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/sqlcompose?label=pre-release&include_prereleases&sort=semver&color=blue)
37
38
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlcompose)
38
-
39
+ [![PyPI Downloads](https://static.pepy.tech/badge/sqlcompose/week)](https://pepy.tech/projects/sqlcompose)
39
40
 
40
41
  # sqlcompose: Composition of linked SQL files
41
42
  sqlcompose allows you to compose sql files from multiple files by introducing `INCLUDE` keywords. The SQL output is composed as CTE's or Common Table Expressions.
@@ -46,8 +47,7 @@ __Execute the script directly:__
46
47
  sqlcompose query.sql
47
48
  ```
48
49
  ```bash
49
- sqlcompose 'select * from $INCLUDE(included-query1.sql)' # on linux
50
- sqlcompose "select * from $INCLUDE(included-query1.sql)" # on windows
50
+ sqlcompose 'select * from $INCLUDE(included-query1.sql)'
51
51
  ```
52
52
 
53
53
  __Import it in another script:__
@@ -1,9 +1,9 @@
1
1
  [![Test](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml)
2
2
  [![Coverage](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml)
3
- ![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)
3
+ [![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/sqlcompose/releases)
4
4
  ![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/sqlcompose?label=pre-release&include_prereleases&sort=semver&color=blue)
5
5
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlcompose)
6
-
6
+ [![PyPI Downloads](https://static.pepy.tech/badge/sqlcompose/week)](https://pepy.tech/projects/sqlcompose)
7
7
 
8
8
  # sqlcompose: Composition of linked SQL files
9
9
  sqlcompose allows you to compose sql files from multiple files by introducing `INCLUDE` keywords. The SQL output is composed as CTE's or Common Table Expressions.
@@ -14,8 +14,7 @@ __Execute the script directly:__
14
14
  sqlcompose query.sql
15
15
  ```
16
16
  ```bash
17
- sqlcompose 'select * from $INCLUDE(included-query1.sql)' # on linux
18
- sqlcompose "select * from $INCLUDE(included-query1.sql)" # on windows
17
+ sqlcompose 'select * from $INCLUDE(included-query1.sql)'
19
18
  ```
20
19
 
21
20
  __Import it in another script:__
@@ -7,7 +7,8 @@ readme = "README.md"
7
7
  authors = [
8
8
  { name = "Anders Madsen", email = "anders.madsen@alphavue.com" }
9
9
  ]
10
- license = { text = "MIT" }
10
+ license = "MIT"
11
+ license-files = [ "LICENSE"]
11
12
  classifiers = [
12
13
  "Development Status :: 5 - Production/Stable",
13
14
  "Development Status :: 6 - Mature",
@@ -21,13 +22,14 @@ classifiers = [
21
22
  "Programming Language :: Python :: 3.11",
22
23
  "Programming Language :: Python :: 3.12",
23
24
  "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
24
26
  "Programming Language :: Python",
25
27
  "Topic :: Software Development :: Libraries :: Python Modules",
26
28
  "Topic :: Software Development :: Libraries",
27
29
  "Typing :: Typed"
28
30
  ]
29
31
  dependencies = []
30
- requires-python = ">=3.10"
32
+ requires-python = ">= 3.10, < 3.15"
31
33
 
32
34
  [project.urls]
33
35
  repository = "https://github.com/apmadsen/sqlcompose"
@@ -41,9 +43,9 @@ test = [
41
43
  "pytest-cov>=6.1.0",
42
44
  ]
43
45
 
44
- [tool.setuptools.dynamic]
45
- version = { attr = 'sqlcompose.__init__.__version__' }
46
+ [tool.setuptools-git-versioning]
47
+ enabled = true
46
48
 
47
49
  [build-system]
48
- requires = ["setuptools >= 77.0.3"]
50
+ requires = ["setuptools >= 77.0.3", "setuptools-git-versioning >= 2.1.0"]
49
51
  build-backend = "setuptools.build_meta"
@@ -1,10 +1,10 @@
1
1
  from sqlcompose.core.functions import load, loads
2
2
  from sqlcompose.core.circular_dependency_error import CircularDependencyError
3
+ from sqlcompose.core.file_not_found_err import FileNotFoundErr
3
4
 
4
5
  __all__ = [
5
6
  'load',
6
7
  'loads',
7
8
  'CircularDependencyError',
8
- ]
9
- __package_name__ = "sqlcompose"
10
- __version__ = "0.0.3"
9
+ 'FileNotFoundErr',
10
+ ]
@@ -1,16 +1,17 @@
1
- from os import path
2
1
  from argparse import ArgumentParser
3
2
 
4
3
  from sqlcompose.core.functions import load, loads
4
+ from sqlcompose.core.compat import is_file
5
+ from sqlcompose.core.file_not_found_err import FileNotFoundErr
5
6
 
6
7
 
7
- def app(args: list[str]) -> tuple[str, int ]:
8
+ def app(args: list[str]) -> tuple[str, int]:
8
9
  try:
9
10
  parser = ArgumentParser(prog = "sqlcompose")
10
11
  parser.add_argument("input", type=str, help = "SQL expression or location of an SQL file")
11
12
  pargs = parser.parse_args(args)
12
13
 
13
- if path.isfile(pargs.input):
14
+ if is_file(pargs.input):
14
15
  sql = load(pargs.input)
15
16
  else:
16
17
  sql = loads(pargs.input)
@@ -18,5 +19,7 @@ def app(args: list[str]) -> tuple[str, int ]:
18
19
  return sql, 0
19
20
  except SystemExit as ex:
20
21
  return str(ex), 2
22
+ except (FileNotFoundErr, FileNotFoundError) as ex:
23
+ return str(ex), 3
21
24
  except Exception as ex: # pragma: no cover
22
25
  return f"Unexpected error: {ex}", 1
@@ -1,5 +1,7 @@
1
- from os import path
1
+ from os import path, sep
2
+ from re import compile
2
3
 
4
+ RX_FILE = compile(r"^[\w,\s-]+\.[A-Za-z]{3}$")
3
5
  WINDOWS_PATH_SEP = "\\"
4
6
  UNIX_PATH_SEP = "/"
5
7
 
@@ -29,4 +31,14 @@ def get_relative_path(file_path: str, root: str) -> str:
29
31
  if root == file_path:
30
32
  return file_path
31
33
  else:
32
- return path.relpath(file_path, path.commonprefix([root, file_path]))
34
+ return path.relpath(file_path, path.commonprefix([root, file_path]))
35
+
36
+ def is_file(text: str) -> bool:
37
+ if path.isfile(text):
38
+ return True
39
+ elif sep in text and is_file(path.basename(text)):
40
+ return True
41
+ elif RX_FILE.match(text):
42
+ return True
43
+
44
+ return False
@@ -0,0 +1,11 @@
1
+
2
+ class FileNotFoundErr(Exception):
3
+ __slots__ = [ "__filename" ]
4
+
5
+ def __init__(self, filename: str, error: str | None = None):
6
+ super().__init__(error or f"File {filename} not found")
7
+ self.__filename = filename
8
+
9
+ @property
10
+ def filename(self) -> str:
11
+ return self.__filename # pragma: no cover
@@ -1,11 +1,11 @@
1
1
  from os import path
2
2
  from typing import Sequence
3
- from os import path
4
3
  from re import compile, sub, escape, IGNORECASE
5
4
  from textwrap import indent
6
5
 
7
6
  from sqlcompose.core.circular_dependency_error import CircularDependencyError
8
7
  from sqlcompose.core.include import Include
8
+ from sqlcompose.core.file_not_found_err import FileNotFoundErr
9
9
  from sqlcompose.core.compat import fix_path, get_relative_path
10
10
 
11
11
  REGEX_INCLUDE = compile(r"\$INCLUDE\(([^\)]+)\)", IGNORECASE)
@@ -37,7 +37,7 @@ def load(filename: str) -> str:
37
37
  filename = fix_path(filename)
38
38
 
39
39
  if not path.isfile(filename):
40
- raise FileNotFoundError(filename)
40
+ raise FileNotFoundErr(filename)
41
41
 
42
42
 
43
43
  with open(filename, "r", encoding="utf-8") as file:
@@ -88,11 +88,13 @@ def compose(
88
88
  )
89
89
  )
90
90
  index = index + 1
91
- except FileNotFoundError:
91
+ except (FileNotFoundErr, FileNotFoundError) as ex:
92
+ filename = get_relative_path(file_path_inner, root)
92
93
  if parent is not None:
93
- raise FileNotFoundError(f"Include failed: File \"{get_relative_path(file_path_inner, root)}\" which was referred to in \"{get_relative_path(parent, root)}\", was not found...")
94
+ raise FileNotFoundErr(filename, f"Include failed: File \"{get_relative_path(file_path_inner, root)}\" which was referred to in \"{get_relative_path(parent, root)}\", was not found...") from ex
94
95
  else:
95
- raise FileNotFoundError(f"Include failed: File \"{get_relative_path(file_path_inner, root)}\" was not found...")
96
+ raise FileNotFoundErr(filename, f"Include failed: File \"{get_relative_path(file_path_inner, root)}\" was not found...") from ex
97
+
96
98
 
97
99
  for include in includes:
98
100
  sql = sub(escape(include.match), include.name, sql)
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlcompose
3
- Version: 0.0.3
3
+ Version: 0.0.4a1
4
4
  Summary: Composition of linked SQL files
5
5
  Author-email: Anders Madsen <anders.madsen@alphavue.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: repository, https://github.com/apmadsen/sqlcompose
8
8
  Keywords: sql,composition,windows,linux
9
9
  Classifier: Development Status :: 5 - Production/Stable
@@ -18,11 +18,12 @@ Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
21
22
  Classifier: Programming Language :: Python
22
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
24
  Classifier: Topic :: Software Development :: Libraries
24
25
  Classifier: Typing :: Typed
25
- Requires-Python: >=3.10
26
+ Requires-Python: <3.15,>=3.10
26
27
  Description-Content-Type: text/markdown
27
28
  License-File: LICENSE
28
29
  Provides-Extra: test
@@ -32,10 +33,10 @@ Dynamic: license-file
32
33
 
33
34
  [![Test](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test.yml)
34
35
  [![Coverage](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/sqlcompose/actions/workflows/python-test-coverage.yml)
35
- ![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)
36
+ [![Stable Version](https://img.shields.io/pypi/v/sqlcompose?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/sqlcompose/releases)
36
37
  ![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/sqlcompose?label=pre-release&include_prereleases&sort=semver&color=blue)
37
38
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlcompose)
38
-
39
+ [![PyPI Downloads](https://static.pepy.tech/badge/sqlcompose/week)](https://pepy.tech/projects/sqlcompose)
39
40
 
40
41
  # sqlcompose: Composition of linked SQL files
41
42
  sqlcompose allows you to compose sql files from multiple files by introducing `INCLUDE` keywords. The SQL output is composed as CTE's or Common Table Expressions.
@@ -46,8 +47,7 @@ __Execute the script directly:__
46
47
  sqlcompose query.sql
47
48
  ```
48
49
  ```bash
49
- sqlcompose 'select * from $INCLUDE(included-query1.sql)' # on linux
50
- sqlcompose "select * from $INCLUDE(included-query1.sql)" # on windows
50
+ sqlcompose 'select * from $INCLUDE(included-query1.sql)'
51
51
  ```
52
52
 
53
53
  __Import it in another script:__
@@ -13,6 +13,7 @@ src/sqlcompose.egg-info/top_level.txt
13
13
  src/sqlcompose/core/app.py
14
14
  src/sqlcompose/core/circular_dependency_error.py
15
15
  src/sqlcompose/core/compat.py
16
+ src/sqlcompose/core/file_not_found_err.py
16
17
  src/sqlcompose/core/functions.py
17
18
  src/sqlcompose/core/include.py
18
19
  tests/test_app.py
@@ -0,0 +1,31 @@
1
+ # ruff: noqa
2
+ # pyright: basic
3
+ from os import path
4
+ from pytest import fixture, raises as assert_raises
5
+
6
+ from sqlcompose.core.app import app
7
+
8
+
9
+ def test_missing_args():
10
+ _result, code = app([])
11
+ assert code == 2
12
+
13
+ def test_existing_file_by_path():
14
+ result, code = app([path.join("tests", "main-query.sql")])
15
+ assert len(result) > 0
16
+ assert code == 0
17
+
18
+ def test_missing_file_by_path():
19
+ result, code = app([path.join("tests", "nonexisting.sql")])
20
+ assert len(result) > 0
21
+ assert code == 3
22
+
23
+ result, code = app([f"SELECT * FROM $INCLUDE({path.join('tests', 'nonexisting.sql')})"])
24
+ assert len(result) > 0
25
+ assert code == 3
26
+
27
+
28
+ def test_sql():
29
+ result, code = app([f"SELECT * FROM $INCLUDE({path.join('tests', 'main-query.sql')})"])
30
+ assert len(result) > 0
31
+ assert code == 0
@@ -0,0 +1,48 @@
1
+ # ruff: noqa
2
+ # pyright: basic
3
+ from pytest import fixture, raises as assert_raises
4
+ from sys import platform
5
+
6
+ from sqlcompose.core.compat import fix_path, get_relative_path
7
+
8
+
9
+ def test_fix_path():
10
+ if platform == "win32":
11
+ tests = {
12
+ "sql\\file.sql" : "sql\\file.sql",
13
+ "sql\\file.sql" : "sql/file.sql",
14
+ }
15
+ else:
16
+ tests = {
17
+ "sql/file.sql" : "sql\\file.sql",
18
+ "sql/file.sql" : "sql/file.sql",
19
+ }
20
+
21
+ for expected_result, file_path in tests.items():
22
+ result = fix_path(file_path)
23
+ assert result == expected_result
24
+
25
+
26
+ def test_get_relative_path():
27
+ if platform == "win32":
28
+ tests = {
29
+ "sql\\file.sql" : ("sql\\file.sql", "sql\\file.sql"),
30
+ "sql\\file.sql" : ("sql\\file.sql", "c:\\app\\"),
31
+ "sql\\file.sql" : ("c:\\app\\sql\\file.sql", "c:\\app\\"),
32
+ }
33
+
34
+ p = "sql\\file.sql"
35
+ assert p == get_relative_path(p, p)
36
+ else:
37
+ tests = {
38
+ "sql/file.sql" : ("sql/file.sql", "sql/file.sql"),
39
+ "sql/file.sql" : ("sql/file.sql", "/app/"),
40
+ "sql/file.sql" : ("/app/sql/file.sql", "/app/"),
41
+ }
42
+ p = "sql/file.sql"
43
+ assert p == get_relative_path(p, p)
44
+
45
+ for expected_result, (file_path, root) in tests.items():
46
+ result = get_relative_path(file_path, root)
47
+ assert result == expected_result
48
+
@@ -0,0 +1,42 @@
1
+ # ruff: noqa
2
+ # pyright: basic
3
+ from pytest import fixture, raises as assert_raises
4
+
5
+ from sqlcompose import loads, load, CircularDependencyError, FileNotFoundErr
6
+ from sqlcompose.core.functions import compose
7
+
8
+
9
+ def test_nonexisting():
10
+ with assert_raises(FileNotFoundErr):
11
+ load("nonexisting.sql")
12
+ with assert_raises(FileNotFoundErr):
13
+ load("tests/non_existing_include.sql")
14
+ with assert_raises(FileNotFoundErr):
15
+ compose("select * from $INCLUDE(some_file_that_does_not_exist.sql)", "SQL", ".", ".")
16
+
17
+
18
+ filename = "tests/existing_include.sql"
19
+ with open(filename, "r", encoding="utf-8") as file:
20
+ with assert_raises(FileNotFoundErr):
21
+ compose(file.read(), filename, filename, ".")
22
+
23
+ def test_reuse_composition():
24
+ result = compose("select * from $INCLUDE(tests/includes/included-query3.sql)", "SQL", ".", ".")
25
+ # print(result)
26
+ assert len(result) > 0
27
+
28
+
29
+ def test_existing_file_by_path():
30
+ result = load("tests/main-query.sql")
31
+ # print(result)
32
+ assert len(result) > 0
33
+
34
+ def test_sql():
35
+ result = loads("SELECT * FROM $INCLUDE(tests/main-query.sql)")
36
+ # print(result)
37
+ assert len(result) > 0
38
+
39
+ def test_circular_dependency():
40
+ with assert_raises(CircularDependencyError):
41
+ load("tests/circular_left.sql")
42
+
@@ -1,29 +0,0 @@
1
- # pyright: basic
2
- from unittest import TestCase, main
3
-
4
- from sqlcompose.core.app import app
5
-
6
- class Test(TestCase):
7
- # def test_nonexisting(self):
8
- # _result, code = app(["nonexisting.sql"])
9
- # self.assertEqual(code, 1)
10
-
11
- def test_missing_args(self):
12
- _result, code = app([])
13
- self.assertEqual(code, 2)
14
-
15
- def test_existing_file_by_path(self):
16
- result, code = app(["tests/main-query.sql"])
17
- self.assertGreater(len(result), 0)
18
- self.assertEqual(code, 0)
19
-
20
- def test_sql(self):
21
- result, code = app(["SELECT * FROM $INCLUDE(tests/main-query.sql)"])
22
- # print(result)
23
- self.assertGreater(len(result), 0)
24
- self.assertEqual(code, 0)
25
-
26
-
27
- if __name__ == '__main__':
28
- main()
29
-
@@ -1,52 +0,0 @@
1
- # pyright: basic
2
- from unittest import TestCase, main
3
- from sys import platform
4
-
5
- from sqlcompose.core.compat import fix_path, get_relative_path
6
-
7
- class Test(TestCase):
8
-
9
- def test_fix_path(self):
10
- if platform == "win32":
11
- tests = {
12
- "sql\\file.sql" : "sql\\file.sql",
13
- "sql\\file.sql" : "sql/file.sql",
14
- }
15
- else:
16
- tests = {
17
- "sql/file.sql" : "sql\\file.sql",
18
- "sql/file.sql" : "sql/file.sql",
19
- }
20
-
21
- for expected_result, file_path in tests.items():
22
- result = fix_path(file_path)
23
- self.assertEqual(result, expected_result)
24
-
25
-
26
- def test_get_relative_path(self):
27
- if platform == "win32":
28
- tests = {
29
- "sql\\file.sql" : ("sql\\file.sql", "sql\\file.sql"),
30
- "sql\\file.sql" : ("sql\\file.sql", "c:\\app\\"),
31
- "sql\\file.sql" : ("c:\\app\\sql\\file.sql", "c:\\app\\"),
32
- }
33
-
34
- p = "sql\\file.sql"
35
- self.assertEqual(p, get_relative_path(p, p))
36
- else:
37
- tests = {
38
- "sql/file.sql" : ("sql/file.sql", "sql/file.sql"),
39
- "sql/file.sql" : ("sql/file.sql", "/app/"),
40
- "sql/file.sql" : ("/app/sql/file.sql", "/app/"),
41
- }
42
- p = "sql/file.sql"
43
- self.assertEqual(p, get_relative_path(p, p))
44
-
45
- for expected_result, (file_path, root) in tests.items():
46
- result = get_relative_path(file_path, root)
47
- self.assertEqual(result, expected_result)
48
-
49
-
50
- if __name__ == '__main__':
51
- main()
52
-
@@ -1,40 +0,0 @@
1
- # pyright: basic
2
- from unittest import TestCase, main
3
-
4
- from sqlcompose import loads, load, CircularDependencyError
5
- from sqlcompose.core.functions import compose
6
-
7
- class Test(TestCase):
8
- def test_nonexisting(self):
9
- self.assertRaises(FileNotFoundError, load, "nonexisting.sql")
10
- self.assertRaises(FileNotFoundError, load, "tests/non_existing_include.sql")
11
- self.assertRaises(FileNotFoundError, compose, "select * from $INCLUDE(some_file_that_does_not_exist.sql)", "SQL", ".", ".")
12
-
13
- filename = "tests/existing_include.sql"
14
- with open(filename, "r", encoding="utf-8") as file:
15
- self.assertRaises(FileNotFoundError, compose, file.read(), filename, filename, ".")
16
-
17
- def test_reuse_composition(self):
18
- result = compose("select * from $INCLUDE(tests/includes/included-query3.sql)", "SQL", ".", ".")
19
- # print(result)
20
- self.assertTrue(len(result) > 0)
21
-
22
-
23
- def test_existing_file_by_path(self):
24
- result = load("tests/main-query.sql")
25
- # print(result)
26
- self.assertTrue(len(result) > 0)
27
-
28
- def test_sql(self):
29
- result = loads("SELECT * FROM $INCLUDE(tests/main-query.sql)")
30
- # print(result)
31
- self.assertTrue(len(result) > 0)
32
-
33
- def test_circular_dependency(self):
34
- self.assertRaises(CircularDependencyError, load, "tests/circular_left.sql")
35
-
36
-
37
-
38
- if __name__ == '__main__':
39
- main()
40
-
File without changes