Example #1
0
 def test_instantiate(self):
     assert Metaspace() is not None
     assert Metaspace(replacement="-") is not None
     with pytest.raises(Exception, match="replacement must be a character"):
         Metaspace(replacement="")
     assert Metaspace(add_prefix_space=True) is not None
     assert isinstance(Metaspace(), Decoder)
Example #2
0
    def test_can_modify(self):
        decoder = Metaspace(replacement="*", add_prefix_space=False)

        assert decoder.replacement == "*"
        assert decoder.add_prefix_space == False

        # Modify these
        decoder.replacement = "&"
        assert decoder.replacement == "&"
        decoder.add_prefix_space = True
        assert decoder.add_prefix_space == True
Example #3
0
 def test_instantiate(self):
     assert Metaspace() is not None
     assert Metaspace(replacement="-") is not None
     with pytest.raises(ValueError, match="expected a string of length 1"):
         Metaspace(replacement="")
     assert Metaspace(add_prefix_space=True) is not None
     assert isinstance(Metaspace(), Decoder)
     assert isinstance(Metaspace(), Metaspace)
     assert isinstance(pickle.loads(pickle.dumps(Metaspace())), Metaspace)
Example #4
0
 def test_decoding(self):
     decoder = Metaspace()
     assert decoder.decode(["▁My", "▁name", "▁is",
                            "▁John"]) == "My name is John"
     decoder = Metaspace(replacement="-", add_prefix_space=False)
     assert decoder.decode(["-My", "-name", "-is",
                            "-John"]) == " My name is John"