Skip to content

Commit

Permalink
Tests for merging directory and file with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
joapuiib committed Nov 26, 2024
1 parent 9cb7a75 commit 1cbf101
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions tests/data/a.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
a1: 1
a2: text
number: 1
string: text
2 changes: 2 additions & 0 deletions tests/data/dir1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
number: 1
string: text
4 changes: 2 additions & 2 deletions tests/data/dir1/b.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
b1: 2
b2: text
number: 2
string: text
4 changes: 2 additions & 2 deletions tests/data/dir2/c.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"c1": 3,
"c2": "text"
"number": 3,
"string": "text"
}
12 changes: 6 additions & 6 deletions tests/docs/test_dir_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ title: "Test Directory Source"
---

- data.a: `{{ data.a }}`
- data.a.a1: `{{ data.a.a1 }}`
- data.a.a2: `{{ data.a.a2 }}`
- data.dir1.b.b1: `{{ data.dir1.b.b1 }}`
- data.dir1.b.b2: `{{ data.dir1.b.b2 }}`
- data.dir2.c.c1: `{{ data.dir2.c.c1 }}`
- data.dir2.c.c2: `{{ data.dir2.c.c2 }}`
- data.a.number: `{{ data.a.number }}`
- data.a.string: `{{ data.a.string }}`
- data.dir1.b.number: `{{ data.dir1.b.number }}`
- data.dir1.b.string: `{{ data.dir1.b.string }}`
- data.dir2.c.number: `{{ data.dir2.c.number }}`
- data.dir2.c.string: `{{ data.dir2.c.string }}`
14 changes: 7 additions & 7 deletions tests/test_data_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def test_dir_source_in_markdown_file():
data_loaded = re.findall(r"<code>([^<]*)", f.read())
print(data_loaded)
assert(data_loaded == [
"{'a1': 1, 'a2': 'text'}", # data/a.yml
"1", # data/a.yml -> a1
"text", # data/a.yml -> a2
"2", # data/dir1/b.yml -> b1
"text", # data/dir1/b.yml -> b2
"3", # data/dir2/c.yml -> c1
"text", # data/dir2/c.yml -> c2
"{'number': 1, 'string': 'text'}", # data/a.yml
"1", # data/a.yml -> number
"text", # data/a.yml -> string
"2", # data/dir1/b.yml -> number
"text", # data/dir1/b.yml -> string
"3", # data/dir2/c.yml -> number
"text", # data/dir2/c.yml -> string
])

def test_file_source_in_markdown_file():
Expand Down
28 changes: 16 additions & 12 deletions tests/test_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ def test_folder_source():

assert data == {
"a": {
"a1": 1,
"a2": "text",
"number": 1,
"string": "text",
},
"dir1": {
"number": 1,
"string": "text",
"b": {
"b1": 2,
"b2": "text",
"number": 2,
"string": "text",
},
},
"dir2": {
"c": {
"c1": 3,
"c2": "text",
"number": 3,
"string": "text",
},
},
}
Expand All @@ -64,19 +66,21 @@ def test_folder_source_slash():

assert data == {
"a": {
"a1": 1,
"a2": "text",
"number": 1,
"string": "text",
},
"dir1": {
"number": 1,
"string": "text",
"b": {
"b1": 2,
"b2": "text",
"number": 2,
"string": "text",
},
},
"dir2": {
"c": {
"c1": 3,
"c2": "text",
"number": 3,
"string": "text",
},
},
}
Expand Down

0 comments on commit 1cbf101

Please sign in to comment.