Skip to content

Commit

Permalink
set working dir to test dir in snippet tests
Browse files Browse the repository at this point in the history
allow to import snippets from any file
  • Loading branch information
sh-rp committed Sep 11, 2023
1 parent 0562a42 commit 594b618
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions docs/website/docs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from tests.utils import patch_home_dir, autouse_test_storage, preserve_environ, duckdb_pipeline_location, wipe_pipeline

@pytest.fixture(autouse=True)
def set_working_dir():
def set_working_dir(request):
# always set working dir to main website folder
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
dname = os.path.dirname(request.module.__file__)
os.chdir(dname)

def pytest_configure(config):
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Make sure that your `dlt` version is **0.3.15** or above. Check it in the termin

Let's load a list of Python objects (dictionaries) into `duckdb` and inspect the created dataset:

<!--@@@DLT_SNIPPET_START start-->
<!--@@@DLT_SNIPPET_START ./getting-started-snippets.py::start-->
```python
import dlt

Expand All @@ -58,7 +58,7 @@ load_info = pipeline.run(data, table_name="users")

print(load_info)
```
<!--@@@DLT_SNIPPET_END start-->
<!--@@@DLT_SNIPPET_END ./getting-started-snippets.py::start-->

Save this python script with the name `quick_start_pipeline.py` and run the following command:

Expand Down
6 changes: 3 additions & 3 deletions docs/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "node update_snippets.js --watch & docusaurus start",
"build": "node update_snippets.js && docusaurus build",
"build:netlify": "node update_snippets.js && docusaurus build --out-dir build/docs",
"start": "node tools/update_snippets.js --watch & docusaurus start",
"build": "node tools/update_snippets.js && docusaurus build",
"build:netlify": "node tools/update_snippets.js && docusaurus build --out-dir build/docs",
"swizzle": "docusaurus swizzle",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const dedent = require('dedent');
var watch = require('node-watch');

const BASE_DIR = "./docs";
const BASE_DIR = "./docs/";
const DOCS_EXTENSIONS = [".md", ".mdx"];
const SNIPPETS_FILE_SUFFIX = "-snippets.py"

Expand Down Expand Up @@ -67,7 +67,12 @@ function buildSnippetMap(lines, fileName) {
// get the right snippet for a file
function getSnippet(fileName, snippetName) {
const ext = path.extname(fileName);
const snippetsFileName = fileName.slice(0, -ext.length) + SNIPPETS_FILE_SUFFIX;
const snippetParts = snippetName.split("::");
let snippetsFileName = fileName.slice(0, -ext.length) + SNIPPETS_FILE_SUFFIX;
if (snippetParts.length > 1) {
snippetsFileName = BASE_DIR + snippetParts[0];
snippetName = snippetParts[1];
}
const lines = fs.readFileSync(snippetsFileName, 'utf8').split(/\r?\n/);
const snippetMap = buildSnippetMap(lines, snippetsFileName);

Expand Down

0 comments on commit 594b618

Please sign in to comment.