string_replacement.py 295 B

1234567891011121314
  1. import pytest
  2. import re
  3. def test_string_rep():
  4. cases = ['', ' ', 'a', 'a s !']
  5. expected = ['', '%20', 'a', 'a%20s%20!']
  6. for c, e in zip(cases, expected):
  7. assert string_rep(c) == e
  8. pytest.main()
  9. def string_rep(input):
  10. p = re.compile(' ')
  11. return p.sub('%20', input)