-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathtest_cli.py
More file actions
110 lines (89 loc) · 4.22 KB
/
Copy pathtest_cli.py
File metadata and controls
110 lines (89 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""CLI structure tests for nano3 commands.
Uses ``typer.testing.CliRunner`` for in-process, fast CLI testing.
These tests verify that all nano3 subcommands are importable and registered
correctly — catching import errors (e.g. missing subpackages) before they
reach users.
"""
from __future__ import annotations
import pytest
from typer.testing import CliRunner
from nemotron.cli.bin.nemotron import app
runner = CliRunner()
# Top-level nano3 commands
NANO3_TOP_COMMANDS = ["pretrain", "sft", "rl", "eval", "pipe", "data", "model"]
# nano3 data prep subcommands
NANO3_DATA_PREP_COMMANDS = ["pretrain", "sft", "rl"]
# nano3 data import subcommands
NANO3_DATA_IMPORT_COMMANDS = ["pretrain", "sft", "rl"]
class TestNano3AppStructure:
def test_help_succeeds(self):
result = runner.invoke(app, ["nano3", "--help"])
assert result.exit_code == 0, f"nano3 --help failed: {result.output}"
@pytest.mark.parametrize("command", NANO3_TOP_COMMANDS)
def test_top_command_listed(self, command):
result = runner.invoke(app, ["nano3", "--help"])
assert result.exit_code == 0
assert command in result.output, (
f"'{command}' not found in nano3 --help output"
)
@pytest.mark.parametrize("command", NANO3_TOP_COMMANDS)
def test_top_command_help_succeeds(self, command):
result = runner.invoke(app, ["nano3", command, "--help"])
assert result.exit_code == 0, (
f"nano3 {command} --help failed: {result.output}\n{result.exception}"
)
class TestNano3DataStructure:
def test_data_subcommands_listed(self):
result = runner.invoke(app, ["nano3", "data", "--help"])
assert result.exit_code == 0
assert "prep" in result.output
assert "import" in result.output
def test_data_prep_help_succeeds(self):
result = runner.invoke(app, ["nano3", "data", "prep", "--help"])
assert result.exit_code == 0, (
f"nano3 data prep --help failed: {result.output}"
)
@pytest.mark.parametrize("command", NANO3_DATA_PREP_COMMANDS)
def test_data_prep_subcommand_listed(self, command):
result = runner.invoke(app, ["nano3", "data", "prep", "--help"])
assert result.exit_code == 0
assert command in result.output, (
f"'{command}' not found in nano3 data prep --help output"
)
@pytest.mark.parametrize("command", NANO3_DATA_PREP_COMMANDS)
def test_data_prep_subcommand_help_succeeds(self, command):
result = runner.invoke(app, ["nano3", "data", "prep", command, "--help"])
assert result.exit_code == 0, (
f"nano3 data prep {command} --help failed: {result.output}\n{result.exception}"
)
def test_data_import_help_succeeds(self):
result = runner.invoke(app, ["nano3", "data", "import", "--help"])
assert result.exit_code == 0, (
f"nano3 data import --help failed: {result.output}"
)
@pytest.mark.parametrize("command", NANO3_DATA_IMPORT_COMMANDS)
def test_data_import_subcommand_listed(self, command):
result = runner.invoke(app, ["nano3", "data", "import", "--help"])
assert result.exit_code == 0
assert command in result.output, (
f"'{command}' not found in nano3 data import --help output"
)
@pytest.mark.parametrize("command", NANO3_DATA_IMPORT_COMMANDS)
def test_data_import_subcommand_help_succeeds(self, command):
result = runner.invoke(app, ["nano3", "data", "import", command, "--help"])
assert result.exit_code == 0, (
f"nano3 data import {command} --help failed: {result.output}\n{result.exception}"
)