-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from berenslab/feat-add-pytest
Add Pytest & tests for sample factory
- Loading branch information
Showing
16 changed files
with
194 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import os.path as osp | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class Directories: | ||
cache_dir: str = "cache" | ||
resource_dir: str = osp.join("doom_creator", "resources") # noqa: RUF009 as this is not really a dynamical call | ||
scenario_out_dir: Optional[str] = None | ||
build_dir: Optional[str] = None | ||
textures_dir: Optional[str] = None | ||
assets_dir: Optional[str] = None | ||
scenario_yaml_dir: Optional[str] = None | ||
dataset_dir: Optional[str] = None | ||
cache_dir: Path = "cache" | ||
resource_dir: Path = Path("doom_creator", "resources") | ||
scenario_out_dir: Optional[Path] = None | ||
build_dir: Optional[Path] = None | ||
textures_dir: Optional[Path] = None | ||
assets_dir: Optional[Path] = None | ||
scenario_yaml_dir: Optional[Path] = None | ||
dataset_dir: Optional[Path] = None | ||
|
||
def __post_init__(self): | ||
self.CACHE_DIR = self.cache_dir | ||
self.SCENARIO_OUT_DIR = ( | ||
osp.join(self.CACHE_DIR, "scenarios") | ||
self.CACHE_DIR: Path = self.cache_dir | ||
self.SCENARIO_OUT_DIR: Path = ( | ||
Path(self.CACHE_DIR, "scenarios") | ||
if self.scenario_out_dir is None | ||
else self.scenario_out_dir | ||
) | ||
self.BUILD_DIR = ( | ||
osp.join(self.SCENARIO_OUT_DIR, "build") | ||
self.BUILD_DIR: Path = ( | ||
Path(self.SCENARIO_OUT_DIR, "build") | ||
if self.build_dir is None | ||
else self.build_dir | ||
) | ||
self.TEXTURES_DIR = ( | ||
osp.join(self.CACHE_DIR, "textures") | ||
self.TEXTURES_DIR: Path = ( | ||
Path(self.CACHE_DIR, "textures") | ||
if self.textures_dir is None | ||
else self.textures_dir | ||
) | ||
self.RESOURCE_DIR = self.resource_dir | ||
self.ASSETS_DIR = ( | ||
osp.join(self.RESOURCE_DIR, "assets") | ||
self.RESOURCE_DIR: Path = self.resource_dir | ||
self.ASSETS_DIR: Path = ( | ||
Path(self.RESOURCE_DIR, "assets") | ||
if self.assets_dir is None | ||
else self.assets_dir | ||
) | ||
self.SCENARIO_YAML_DIR = ( | ||
osp.join(self.RESOURCE_DIR, "config") | ||
self.SCENARIO_YAML_DIR: Path = ( | ||
Path(self.RESOURCE_DIR, "config") | ||
if self.scenario_yaml_dir is None | ||
else self.scenario_yaml_dir | ||
) | ||
self.DATASET_DIR = ( | ||
self.DATASET_DIR: Path = ( | ||
self.TEXTURES_DIR if self.dataset_dir is None else self.dataset_dir | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
#=============================================================================== | ||
# Description: Builds the gathering apples scenario used for tests | ||
# | ||
# Arguments: | ||
# $1 - Path to Singularity (.sif) container | ||
# | ||
# Usage: | ||
# tests/ci/build_scenario.sh container.sif | ||
# (run from top level directory!) | ||
#=============================================================================== | ||
|
||
singularity exec "$1" python -m doom_creator.compile_scenario gathering apples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import shutil | ||
import sys | ||
import time | ||
|
||
import hydra | ||
import pytest | ||
from omegaconf import DictConfig, OmegaConf | ||
|
||
sys.path.append(".") | ||
from runner.util import search_conf | ||
|
||
OmegaConf.register_new_resolver("eval", eval) | ||
|
||
|
||
@pytest.fixture | ||
def config() -> DictConfig: | ||
with hydra.initialize(config_path="../../config/base", version_base=None): | ||
experiment = "gathering-apples" | ||
config = hydra.compose( | ||
"config", overrides=[f"+experiment={experiment}", "system.device=cpu"] | ||
) | ||
|
||
# replace the paths that are normally set via HydraConfig | ||
config.path.run_dir = f"tmp{hash(time.time())}" | ||
config.sweep.command[-2] = experiment | ||
|
||
# check whether there's still values to be interpolated through hydra | ||
hydra_values = search_conf( | ||
OmegaConf.to_container(config, resolve=False), "hydra:" | ||
) | ||
|
||
assert ( | ||
len(hydra_values) == 0 | ||
), "hydra: values can not be resolved here. Set them manually in this fixture for tests!" | ||
|
||
OmegaConf.resolve(config) | ||
yield config | ||
|
||
# Cleanup: remove temporary dir | ||
if os.path.exists(config.path.run_dir): | ||
shutil.rmtree(config.path.run_dir) | ||
|
||
|
||
@pytest.fixture | ||
def data_root() -> str: | ||
return "cache" |
Oops, something went wrong.