-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8629da0
commit 87c0405
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .cmd import cli | ||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import click | ||
import json | ||
from trace_dkey import trace | ||
|
||
|
||
@click.command() | ||
@click.option("--file", "-f", required=True, help="Path to the JSON file") | ||
@click.option("--key", "-k", required=False, help="Key to trace in the dictionary") | ||
def cli(file: str, key: str): | ||
with open(file) as file_obj: | ||
dictionary = json.load(file_obj) | ||
|
||
print(trace(dictionary, key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) | ||
from trace_dkey.cmd import cli | ||
|
||
|
||
|
||
@pytest.fixture | ||
def runner(): | ||
return CliRunner() | ||
|
||
|
||
def test_trace_key(runner): | ||
input_json = '{"name": "John Doe", "age": 30}' | ||
expected_output = "[['name']]" | ||
|
||
with runner.isolated_filesystem(): | ||
# Create a temporary test JSON file | ||
with open("test.json", "w") as file: | ||
file.write(input_json) | ||
|
||
result = runner.invoke(cli, ["--file", "test.json", "--key", "name"]) | ||
assert result.exit_code == 0 | ||
assert result.output.strip() == expected_output |