-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_typename.py
72 lines (50 loc) · 2.12 KB
/
test_typename.py
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
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division
import pytest
from ndeftool.cli import main
@pytest.fixture
def runner():
import click.testing
return click.testing.CliRunner()
@pytest.fixture
def isolated_runner(runner):
with runner.isolated_filesystem():
yield runner
def test_help_option_prints_usage(runner):
result = runner.invoke(main, ['typename', '--help'])
assert result.exit_code == 0
assert result.output.startswith('Usage: main typename [OPTIONS] TYPE')
def test_abbreviated_command_name(runner):
result = runner.invoke(main, ['tn', '--help'])
assert result.exit_code == 0
assert result.output.startswith('Usage: main tn [OPTIONS] TYPE')
def test_debug_option_prints_kwargs(isolated_runner):
params = '--debug typename text/plain'.split()
result = isolated_runner.invoke(main, params, input='')
assert result.exit_code == 0
assert result.output.startswith("ndeftool.commands.TypeName {")
def test_typename_as_first_command(runner):
params = 'typename text/plain'.split()
result = runner.invoke(main, params)
assert result.exit_code == 0
assert result.stdout_bytes == b'\xd2\n\x00text/plain'
def test_typename_as_second_command(runner):
params = 'identifier name typename text/plain'.split()
result = runner.invoke(main, params)
assert result.exit_code == 0
assert result.stdout_bytes == b'\xda\n\x00\x04text/plainname'
def test_invalid_type_raises_error(runner):
params = '--silent typename invalid-type'.split()
result = runner.invoke(main, params)
assert result.exit_code == 1
assert 'Error:' in result.output
def test_payload_type_error_raises_error(runner):
params = '--silent payload helloworld typename urn:nfc:wkt:T'.split()
result = runner.invoke(main, params)
assert result.exit_code == 1
assert 'Error:' in result.output
def test_payload_type_error_not_checked(runner):
params = 'payload helloworld typename --no-check urn:nfc:wkt:T'.split()
result = runner.invoke(main, params)
assert result.exit_code == 0
assert result.stdout_bytes == b'\xd1\x01\nThelloworld'