def test_get_path(self): class p: _path: str m_cfg = p() m_cfg._path = 'm' d_cfg = p() d_cfg._path = 'd' d_cfg.index_cross = 1 r_cfg = p() r_cfg._path = 'r' self.assertEqual( get_path(m_cfg, d_cfg, r_cfg), os.path.join(env.getdir(env.paths.save_folder), 'm-r-d-1'))
def setUpClass(cls): cls.path = os.path.join( env.getdir(env.paths.test_folder), os.path.splitext(os.path.basename(__file__))[0], cls.__name__) if not os.path.exists(cls.path): os.makedirs(cls.path) cls.old_save_folder = env.paths.save_folder env.paths.save_folder = os.path.join(env.paths.test_folder, cls.path) class SimpleModel(BaseModel): def __init__(self, cfg, data_cfg, run, **kwargs): super().__init__(cfg, data_cfg, run, **kwargs) self.fc = nn.Linear(6, 3).to(self.device) def train(self, epoch_info, sample_dict): input = sample_dict['input'].to(self.device) target = sample_dict['target'].to(self.device) output = self.fc(input) loss = F.l1_loss(output, target) return {'loss': loss} def test(self, batch_idx, sample_dict): input = sample_dict['input'].to(self.device) output = self.fc(input) return {'output': output} model_path = os.path.join(cls.path, 'model_configs.json') with open(model_path, 'w') as f: f.write(json.dumps(dict(name='SimpleModel'))) dataset_path = os.path.join(cls.path, 'dataset_configs.json') with open(dataset_path, 'w') as f: f.write(json.dumps(dict(index_cross=1))) run_path = os.path.join(cls.path, 'run_configs.json') with open(run_path, 'w') as f: f.write(json.dumps(dict())) cls.model = SimpleModel(BaseConfig(model_path), BaseConfig(dataset_path), Run(run_path))
def setUpClass(cls): cls.path = os.path.join( env.getdir(env.paths.test_folder), os.path.splitext(os.path.basename(__file__))[0], cls.__name__) if not os.path.exists(cls.path): os.makedirs(cls.path)
def test_getdir(self): self.assertTrue( os.path.samefile(env.getdir(env.paths.test_folder), os.path.split(__file__)[0]))