test_simple.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import six # noqa
  2. import library.python.resource as rs
  3. text = b"na gorshke sidel korol\n"
  4. def test_find():
  5. assert rs.find("/qw.txt") == text
  6. def test_iter():
  7. assert set(rs.iterkeys()).issuperset({"/qw.txt", "/prefix/1.txt", "/prefix/2.txt"})
  8. assert set(rs.iterkeys(prefix="/prefix/")) == {"/prefix/1.txt", "/prefix/2.txt"}
  9. assert set(rs.iterkeys(prefix="/prefix/", strip_prefix=True)) == {"1.txt", "2.txt"}
  10. assert set(rs.iteritems(prefix="/prefix")) == {
  11. ("/prefix/1.txt", text),
  12. ("/prefix/2.txt", text),
  13. }
  14. assert set(rs.iteritems(prefix="/prefix", strip_prefix=True)) == {
  15. ("/1.txt", text),
  16. ("/2.txt", text),
  17. }
  18. def test_resfs_files():
  19. metadata_path = "contrib/python/py/py{}/.dist-info/METADATA".format("2" if six.PY2 else "3")
  20. assert metadata_path in set(rs.resfs_files())
  21. def test_resfs_read():
  22. metadata_path = "contrib/python/py/py{}/.dist-info/METADATA".format("2" if six.PY2 else "3")
  23. assert "Metadata-Version" in rs.resfs_read(metadata_path).decode("utf-8")