def test_cache_config_save() -> None: new_config = cache.CacheConfig(enabled=False, default_expiration=364, cache_type='csv') # pylint: disable=protected-access new_config._save() # type: ignore cast(MagicMock, file_utils.safe_jsonify).assert_called_once() # pylint: disable=no-member
def test_enable() -> None: config = cache.CacheConfig() assert not config.enabled config.enable() assert config.enabled config.enable(False) assert not config.enabled
def test_cache_config_singleton() -> None: new_config = cache.CacheConfig(enabled=False, default_expiration=365, cache_type='csv') assert new_config == cache.config assert new_config == cfg assert not cfg.enabled assert cfg.default_expiration == 365 assert cfg.cache_type == 'csv' cache.config.cache_directory = '~/temp' assert cfg.cache_directory == '~/temp'
def test_cache_type_set() -> None: config = cache.CacheConfig(cache_type='parquet') assert config.cache_type == 'parquet'
def test_cache_type_invalid() -> None: with pytest.raises(ValueError): cache.CacheConfig(enabled=False, cache_type='exe')
def test_cache_type_default() -> None: config = cache.CacheConfig() assert config.cache_type == cache.CacheConfig.DEFAULT_CACHE_TYPE
def test_expiration_set() -> None: my_expiration: int = 365 config = cache.CacheConfig(default_expiration=my_expiration) assert config.default_expiration == my_expiration
def test_expiration_default() -> None: config = cache.CacheConfig() assert config.default_expiration == cache.CacheConfig.DEFAULT_EXPIRATION
def test_cache_directory_default(mkdir: MagicMock) -> None: config = cache.CacheConfig() assert config.cache_directory == cache.CacheConfig.DEFAULT_CACHE_DIR assert mkdir.called_once_with(cache.CacheConfig.DEFAULT_CACHE_DIR)
def test_enabled_set() -> None: config = cache.CacheConfig(enabled=True) assert config.enabled
def test_not_enabled_default() -> None: config = cache.CacheConfig() assert not config.enabled
def _cache_config() -> cache.CacheConfig: test_cache_directory = os.path.join(cache.CacheConfig.DEFAULT_CACHE_DIR, '.pytest') config = cache.CacheConfig(enabled=False) config.cache_directory = test_cache_directory return config
if __name__ == "__main__": # Setup profiler profiler = cProfile.Profile() profiler.enable() parser = argparse.ArgumentParser() parser.add_argument('--cache-enabled', action='store_true', default=False) parser.add_argument('--cache-type', default=None) parser.add_argument('--iterations', default=ITERATIONS, type=int) args = parser.parse_args() if args.cache_enabled and args.cache_type is not None: cache.flush() cache.config = cache.CacheConfig(enabled=True, cache_type=args.cache_type) else: cache.disable() # Run profile(get_profile_suite(args.iterations)) # Print stats profiler.disable() stats_stream = io.StringIO() profiler_stats = pstats.Stats(profiler, stream=stats_stream).sort_stats( pstats.SortKey.PCALLS) # type: ignore # TODO: After https://github.com/python/typeshed/pull/4523 is integrated into a mypy release, remove ^ type annotation profiler_stats.print_stats() try: print(stats_stream.getvalue())