def test_cache1(test_env): cache_dir = "elsie-cache" slides = SlideDeck(name_policy="ignore") slide = slides.new_slide() slide.box(show="1+").text("1") slide.box(show="next+").text("2") slide.box(show="next+").text("3") assert not glob.glob("{}/*".format(cache_dir)) slides.render(output="test.pdf") print(glob.glob("{}/*".format(cache_dir))) fs = set(os.path.basename(p) for p in glob.glob("{}/*".format(cache_dir))) assert "queries3.cache" in fs assert len(fs) == 4 slides = SlideDeck(name_policy="ignore") slide = slides.new_slide() slide.box(show="1+").text("1") slide.box(show="next+").text("2") slide.box(show="next+").text("3") slides.render(output="test.pdf") fs2 = set(os.path.basename(p) for p in glob.glob("{}/*".format(cache_dir))) assert fs2 == fs slides = SlideDeck(name_policy="ignore") slide = slides.new_slide() slide.box(show="1+").text("1") slide.box(show="next+").text("2") slide.box(show="next+").text("4") slides.render(output="test.pdf") print(fs2) fs3 = set(os.path.basename(p) for p in glob.glob("{}/*".format(cache_dir))) assert "queries3.cache" in fs3 assert len(fs3.difference(fs)) == 1
def test_name_policy_unique(policy): slides = SlideDeck(name_policy=policy) slides.new_slide() slides.new_slide() slides.new_slide(name="xxx") with pytest.raises(Exception, match="already exists"): slides.new_slide(name="xxx") slides.new_slide(name="yyy") with pytest.raises(Exception, match="has to be a string"): slides.new_slide(name=123) assert len(slides._slides) == 4
def test_name_policy_replace(): slides = SlideDeck(name_policy="replace") slides.new_slide(name="xxx") slides.new_slide(name="yyy") b2 = slides.new_slide(name="xxx") s = slides._slides assert len(s) == 2 assert s[0].name == "yyy" assert s[1].name == "xxx" assert s[1].box() is b2
def test_cache2(test_env): cache_dir = "elsie-cache" slides = SlideDeck(name_policy="ignore") for i in range(10): slide = slides.new_slide() slide.box(width=100, height=100).rect(bg_color="blue") assert not glob.glob("{}/*".format(cache_dir)) slides.render(output="test.pdf") files = set([os.path.basename(p) for p in glob.glob("{}/*".format(cache_dir))]) assert 2 == len(files) slides = SlideDeck(name_policy="ignore") for i in range(10): slide = slides.new_slide() slide.box(width=100, height=100).rect(bg_color="green") slides.render(output="test.pdf") files2 = set([os.path.basename(p) for p in glob.glob("{}/*".format(cache_dir))]) assert 2 == len(files2) assert files != files2
def new_slides(width: int, height: int) -> SlideDeck: return SlideDeck(width=width, height=height)
def test_name_policy_ignore(policy): slides = SlideDeck(name_policy=policy) slides.new_slide(name="xxx") slides.new_slide(name="xxx") slides.new_slide(name="yyy") assert len(slides._slides) == 3
def test_invalid_name_policy(): with pytest.raises(Exception, match="Invalid"): SlideDeck(name_policy="xxx")