Skip to content

Commit b4c929c

Browse files
Fix for command line usage using short interpretatons.
1 parent 35f508d commit b4c929c

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,6 @@ jobs:
156156
- test
157157
steps:
158158
- name: Require all successes
159-
uses: re-actors/alls-green@v1
159+
uses: re-actors/alls-green@v1.2.2
160160
with:
161161
jobs: ${{ toJSON(needs) }}

bitstring.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,17 @@ def __new__(cls, auto: Optional[BitsType] = None, length: Optional[int] = None,
930930

931931
# Dictionary that maps token names to the function that reads them
932932
cls._name_to_read = {'uint': Bits._readuint,
933+
'u': Bits._readuint,
933934
'uintle': Bits._readuintle,
934935
'uintbe': Bits._readuintbe,
935936
'uintne': Bits._readuintne,
936937
'int': Bits._readint,
938+
'i': Bits._readint,
937939
'intle': Bits._readintle,
938940
'intbe': Bits._readintbe,
939941
'intne': Bits._readintne,
940942
'float': Bits._readfloatbe,
943+
'f': Bits._readfloatbe,
941944
'floatbe': Bits._readfloatbe, # floatbe is a synonym for float
942945
'floatle': Bits._readfloatle,
943946
'floatne': Bits._readfloatne,
@@ -946,8 +949,11 @@ def __new__(cls, auto: Optional[BitsType] = None, length: Optional[int] = None,
946949
'bfloatle': Bits._readbfloatle,
947950
'bfloatne': Bits._readbfloatne,
948951
'hex': Bits._readhex,
952+
'h': Bits._readhex,
949953
'oct': Bits._readoct,
954+
'o': Bits._readoct,
950955
'bin': Bits._readbin,
956+
'b': Bits._readbin,
951957
'bits': Bits._readbits,
952958
'bytes': Bits._readbytes,
953959
'ue': Bits._readue,
@@ -4742,7 +4748,8 @@ def main() -> None:
47424748
$ python -m bitstring hex=01, uint:12=352.hex
47434749
01160
47444750
""")
4745-
elif fp in dummy._name_to_read.keys():
4751+
return
4752+
if fp in dummy._name_to_read.keys():
47464753
# concatenate all other parameters and interpret using the final one
47474754
b1 = Bits(','.join(sys.argv[1: -1]))
47484755
print(b1._readtoken(fp, 0, b1.__len__())[0])

tests/test_bitstring.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,29 @@ def testRunningModuleWithSingleParameter(self):
106106

107107
def testRunningModuleWithSingleParameterAndInterpretation(self):
108108
with redirect_stdout(io.StringIO()) as f:
109-
with mock.patch('sys.argv', ['ignored', 'u12=352', 'int']):
109+
with mock.patch('sys.argv', ['ignored', 'u12=352', 'i']):
110110
bitstring.main()
111111
s = f.getvalue()
112112
self.assertEqual(s, '352\n')
113113

114114
def testRunningModuleWithMultipleParameters(self):
115115
with redirect_stdout(io.StringIO()) as f:
116-
with mock.patch('sys.argv', ['b.py', 'uint:12=352', '0b101', '0o321', 'f32=51', 'bin:1=1']):
116+
with mock.patch('sys.argv', ['b.py', 'uint12=352', '0b101', '0o321', 'f32=51', 'bool=1']):
117117
bitstring.main()
118118
s = f.getvalue()
119119
self.assertEqual(s, '0x160ad1424c0000, 0b1\n')
120120

121-
# def testRunningModuleWithMultipleParametersAndInterpretation(self):
122-
# with redirect_stdout(io.StringIO()) as f:
123-
# with mock.patch('sys.argv', ['b.py', 'ue=1000', '0xff.b']):
124-
# bitstring.main()
125-
# s = f.getvalue()
126-
# self.assertEqual(s, '000000000111110100111111111\n')
121+
def testRunningModuleWithMultipleParametersAndInterpretation(self):
122+
with redirect_stdout(io.StringIO()) as f:
123+
with mock.patch('sys.argv', ['b.py', 'ue=1000', '0xff.bin']):
124+
bitstring.main()
125+
s = f.getvalue()
126+
self.assertEqual(s, '000000000111110100111111111\n')
127+
128+
def testShortInterpretations(self):
129+
with redirect_stdout(io.StringIO()) as f:
130+
with mock.patch('sys.argv', ['b.py', 'bin=001.b']):
131+
bitstring.main()
132+
s = f.getvalue()
133+
self.assertEqual(s, '001\n')
134+

0 commit comments

Comments
 (0)