def test_digest_file(tmp_path): """Test that a config file can be digested programatically.""" with tempconfig({}): tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) tmp_cfg.write(""" [CLI] media_dir = this_is_my_favorite_path video_dir = {media_dir}/videos """) tmp_cfg.close() config.digest_file(tmp_cfg.name) assert config.get_dir("media_dir") == Path("this_is_my_favorite_path") assert config.get_dir("video_dir") == Path( "this_is_my_favorite_path/videos")
def using_temp_config(tmpdir): """Standard fixture that makes tests use a standard_config.cfg with a temp dir.""" with tempconfig( config.digest_file( Path(__file__).parent.parent / "standard_config.cfg"), ): config.media_dir = tmpdir yield
def test_frame_size(using_opengl_renderer, tmp_path): """Test that the frame size can be set via config file.""" np.testing.assert_allclose( config.aspect_ratio, config.pixel_width / config.pixel_height ) np.testing.assert_allclose(config.frame_height, 8.0) with tempconfig({}): tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) tmp_cfg.write( """ [CLI] pixel_height = 10 pixel_width = 10 """, ) tmp_cfg.close() config.digest_file(tmp_cfg.name) # aspect ratio is set using pixel measurements np.testing.assert_allclose(config.aspect_ratio, 1.0) # if not specified in the cfg file, frame_width is set using the aspect ratio np.testing.assert_allclose(config.frame_height, 8.0) np.testing.assert_allclose(config.frame_width, 8.0) with tempconfig({}): tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) tmp_cfg.write( """ [CLI] pixel_height = 10 pixel_width = 10 frame_height = 10 frame_width = 10 """, ) tmp_cfg.close() config.digest_file(tmp_cfg.name) np.testing.assert_allclose(config.aspect_ratio, 1.0) # if both are specified in the cfg file, the aspect ratio is ignored np.testing.assert_allclose(config.frame_height, 10.0) np.testing.assert_allclose(config.frame_width, 10.0)
def test_digest_file(tmp_path): """Test that a config file can be digested programmatically.""" with tempconfig({}): tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) tmp_cfg.write( """ [CLI] media_dir = this_is_my_favorite_path video_dir = {media_dir}/videos sections_dir = {media_dir}/{scene_name}/prepare_for_unforeseen_consequences frame_height = 10 """, ) tmp_cfg.close() config.digest_file(tmp_cfg.name) assert config.get_dir("media_dir") == Path("this_is_my_favorite_path") assert config.get_dir("video_dir") == Path( "this_is_my_favorite_path/videos") assert config.get_dir("sections_dir", scene_name="test") == Path( "this_is_my_favorite_path/test/prepare_for_unforeseen_consequences" )