Exemple #1
0
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']
Exemple #2
0
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']
Exemple #3
0
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']
Exemple #4
0
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']
Exemple #5
0
 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
Exemple #6
0
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']
Exemple #7
0
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'
    ]
Exemple #8
0
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'
    ]
Exemple #9
0
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'
    ]
Exemple #10
0
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']
Exemple #11
0
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']
Exemple #12
0
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')
Exemple #13
0
def test_xlate_filter_datafmt():
    with pytest.raises(ValueError):
        make_translation_filter(size=8,
                                datafmt='InVaLiD',
                                translations=[(8, 'Eight', 'Red')])
Exemple #14
0
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')])
Exemple #15
0
def test_xlate_filter_datafmt():
    with pytest.raises(ValueError):
        make_translation_filter(size=8, datafmt='InVaLiD',
                                translations=[(8, 'Eight', 'Red')])
Exemple #16
0
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')])
Exemple #17
0
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')