def test_xlate_filter_decimal(): xlatef = make_translation_filter( datafmt='dec', translations=[(1, "X"), (1234, "XXXX"), (123456789, "XXXXXXXXX")], ) assert xlatef.splitlines() == ['1 X', '1234 XXXX', '123456789 XXXXXXXXX']
def test_xlate_filter_bin(): xlatef = make_translation_filter(size=2, datafmt='bin', translations=[(0, "Zero"), (1, "One"), (2, "Two")]) assert xlatef.splitlines() == ['00 Zero', '01 One', '10 Two']
def test_xlate_filter_bin(): xlatef = make_translation_filter(size=2, datafmt='bin', translations=[ (0, "Zero"), (1, "One"), (2, "Two"), ]) assert xlatef.splitlines() == ['00 Zero', '01 One', '10 Two']
def test_xlate_filter_decimal(): xlatef = make_translation_filter(datafmt='dec', translations=[ (1, "X"), (1234, "XXXX"), (123456789, "XXXXXXXXX"), ]) assert xlatef.splitlines() == ['1 X', '1234 XXXX', '123456789 XXXXXXXXX']
def make_fsm_state_translation(self, fsm: FSM) -> str: # generate filter file from vcd.gtkw import make_translation_filter translations = list(fsm.decoding.items()) filename = "filter__{}.txt".format( self._strip_bits(self.name(fsm.state))) filepath = os.path.join(self.filtersdir, filename) with open(filepath, 'w') as f: f.write(make_translation_filter(translations, size=len(fsm.state))) return filepath
def test_xlate_filter(): xlatef = make_translation_filter(size=8, translations=[ (16, "Sixteen", "Magenta"), (32, "Thirty-two"), (-128, "Negative"), (255, "Two Five Five", "Blue"), ]) assert xlatef.splitlines() == ['10 ?Magenta?Sixteen', '20 Thirty-two', '80 Negative', 'ff ?Blue?Two Five Five']
def test_xlate_filter_ascii(): xlatef = make_translation_filter(datafmt='ascii', translations=[ ('a', 'Aye'), ('+', 'Plus', 'Red'), ('!', 'Bang'), (35, 'Pound', 'Blue'), ]) assert xlatef.splitlines() == [ 'a Aye', '+ ?Red?Plus', '! Bang', '# ?Blue?Pound' ]
def test_xlate_filter_real(): xlatef = make_translation_filter(datafmt='real', translations=[ (123, 'One two three'), (44.0, 'Forty-four'), (1.23, 'One point two three'), (-17.5, 'Sub zero'), ]) assert xlatef.splitlines() == [ '123 One two three', '44 Forty-four', '1.23 One point two three', '-17.5 Sub zero' ]
def test_xlate_filter(): xlatef = make_translation_filter(size=8, translations=[ (16, "Sixteen", "Magenta"), (32, "Thirty-two"), (-128, "Negative"), (255, "Two Five Five", "Blue"), ]) assert xlatef.splitlines() == [ '10 ?Magenta?Sixteen', '20 Thirty-two', '80 Negative', 'ff ?Blue?Two Five Five' ]
def test_xlate_filter_real(): xlatef = make_translation_filter(datafmt='real', translations=[ (123, 'One two three'), (44.0, 'Forty-four'), (1.23, 'One point two three'), (-17.5, 'Sub zero'), ]) assert xlatef.splitlines() == [ '123 One two three', '44 Forty-four', '1.23 One point two three', '-17.5 Sub zero']
def test_xlate_filter_ascii(): xlatef = make_translation_filter(datafmt='ascii', translations=[ ('a', 'Aye'), ('+', 'Plus', 'Red'), ('!', 'Bang'), (35, 'Pound', 'Blue'), ]) assert xlatef.splitlines() == [ 'a Aye', '+ ?Red?Plus', '! Bang', '# ?Blue?Pound']
def test_xlate_filter_invalid_ascii(): with pytest.raises(ValueError): make_translation_filter(datafmt='ascii', translations=[('abc', 'ABC')]) with pytest.raises(TypeError): make_translation_filter([(35.0, 'Pound')], datafmt='ascii')
def test_xlate_filter_datafmt(): with pytest.raises(ValueError): make_translation_filter(size=8, datafmt='InVaLiD', translations=[(8, 'Eight', 'Red')])
def test_xlate_filter_size(): with pytest.raises(ValueError): # 8 does not fit in 3-bits. make_translation_filter(size=3, datafmt='oct', translations=[(8, 'Eight', 'Red')])
def test_xlate_filter_datafmt(): with pytest.raises(ValueError): make_translation_filter(size=8, datafmt='InVaLiD', translations=[(8, 'Eight', 'Red')])
def test_xlate_filter_size(): with pytest.raises(ValueError): # 8 does not fit in 3-bits. make_translation_filter(size=3, datafmt='oct', translations=[(8, 'Eight', 'Red')])
def test_xlate_filter_invalid_ascii(): with pytest.raises(ValueError): make_translation_filter(datafmt='ascii', translations=[('abc', 'ABC')]) with pytest.raises(TypeError): make_translation_filter([(35.0, 'Pound')], datafmt='ascii')