77except ImportError :
88 micropython = None
99
10+ _app_kwargs = {}
11+
1012try :
1113 from unittest .mock import patch
1214
1315 from tamp .cli .main import app
1416except ImportError :
1517 pass
18+ else :
19+ from importlib .metadata import version
20+
21+ from packaging .version import Version
22+
23+ _cyclopts_version = Version (version ("cyclopts" ))
24+ _app_kwargs = {"result_action" : "return_value" } if _cyclopts_version >= Version ("4.0.0" ) else {}
1625
1726compressed_foo_foo_foo = bytes (
1827 # fmt: off
1928 [
2029 0b010_11_00_0 , # header (window_bits=10, literal_bits=8)
21- 0b1_0110011 , # literal "f"
30+ 0b1_0110011 , # literal "f"
2231 0b0_0_0_00100 , # the pre-init buffer contains "oo" at index 131
23- # size=2 -> 0b0
24- # 131 -> 0b0010000011
25- 0b00011_1_00 , # literal " "
26- 0b100000_0_1 , # There is now "foo " at index 0
27- 0b000_00000 , # size=4 -> 0b1000
28- 0b00000_0_11 , # Just "foo" at index 0; size=3 -> 0b11
29- 0b00000000 , # index 0 -> 0b0000000000
30- 0b00_000000 , # 6 bits of zero-padding
32+ # size=2 -> 0b0
33+ # 131 -> 0b0010000011
34+ 0b00011_1_00 , # literal " "
35+ 0b100000_0_1 , # There is now "foo " at index 0
36+ 0b000_00000 , # size=4 -> 0b1000
37+ 0b00000_0_11 , # Just "foo" at index 0; size=3 -> 0b11
38+ 0b00000000 , # index 0 -> 0b0000000000
39+ 0b00_000000 , # 6 bits of zero-padding
3140 ]
3241 # fmt: on
3342)
@@ -42,14 +51,14 @@ def test_compress_file_to_stdout(self):
4251 test_file .write_bytes (b"foo foo foo" )
4352
4453 with patch ("sys.stdout.buffer.write" ) as mock_stdout :
45- app (["compress" , str (test_file )])
54+ app (["compress" , str (test_file )], ** _app_kwargs )
4655 mock_stdout .assert_called_once_with (compressed_foo_foo_foo )
4756
4857 def test_compress_stdin_to_stdout (self ):
4958 with patch ("sys.stdout.buffer.write" ) as mock_stdout , patch (
5059 "sys.stdin.buffer.read" , return_value = "foo foo foo"
5160 ):
52- app ("compress" )
61+ app ("compress" , ** _app_kwargs )
5362 mock_stdout .assert_called_once_with (compressed_foo_foo_foo )
5463
5564 def test_decompress_file_to_stdout (self ):
@@ -58,14 +67,14 @@ def test_decompress_file_to_stdout(self):
5867 test_file = tmp_dir / "test_input.tamp"
5968 test_file .write_bytes (compressed_foo_foo_foo )
6069 with patch ("sys.stdout.buffer.write" ) as mock_stdout :
61- app (["decompress" , str (test_file )])
70+ app (["decompress" , str (test_file )], ** _app_kwargs )
6271 mock_stdout .assert_called_once_with (b"foo foo foo" )
6372
6473 def test_decompress_stdin_to_stdout (self ):
6574 with patch ("sys.stdout.buffer.write" ) as mock_stdout , patch (
6675 "sys.stdin.buffer.read" , return_value = compressed_foo_foo_foo
6776 ):
68- app ("decompress" )
77+ app ("decompress" , ** _app_kwargs )
6978 mock_stdout .assert_called_once_with (b"foo foo foo" )
7079
7180 def test_decompress_stdin_to_file (self ):
@@ -74,5 +83,5 @@ def test_decompress_stdin_to_file(self):
7483 test_file = tmp_dir / "test_output.txt"
7584
7685 with patch ("sys.stdin.buffer.read" , return_value = compressed_foo_foo_foo ):
77- app (["decompress" , "-o" , str (test_file )])
86+ app (["decompress" , "-o" , str (test_file )], ** _app_kwargs )
7887 self .assertEqual (test_file .read_text (), "foo foo foo" )
0 commit comments