Skip to content

Commit

Permalink
Add test for sending content to STDERR as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Nov 8, 2024
1 parent a4a7b95 commit 8e97719
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/carbon_txt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
help="Validate carbon.txt files, either online, or locally.",
)

err_console = rich.console.Console(stderr=True)


file_finder = finders.FileFinder()
parser = parsers_toml.CarbonTxtParser()
Expand Down Expand Up @@ -103,8 +105,6 @@ def validate_file(
_log_validated_carbon_txt_object(validation_results)
return 1

return parsed_result


@app.command()
def schema():
Expand All @@ -113,8 +113,13 @@ def schema():
"""
schema = CarbonTxtFile.model_json_schema()

rich.print(json.dumps(schema, indent=2))
return schema
err_console.print("JSON Schema for a carbon.txt file: \n")

if sys.stdout.isatty():
rich.print(json.dumps(schema, indent=2))
else:
print(json.dumps(schema, indent=2))
return 0


def configure_django(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from carbon_txt.cli import app

runner = CliRunner()
runner = CliRunner(mix_stderr=False)


class TestCLI:
Expand Down Expand Up @@ -46,5 +46,6 @@ def test_schema(self):
parsed_schema = json.loads(result.stdout)

assert result.exit_code == 0
assert "JSON Schema for a carbon.txt file" in result.stderr
assert "CarbonTxtFile" in parsed_schema.get("title")
assert "$defs" in parsed_schema.keys()

0 comments on commit 8e97719

Please sign in to comment.