Skip to content

Commit

Permalink
added load
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Sep 27, 2024
1 parent d20aec1 commit 4836abf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path
from typing import List
from typing import Optional

from easyscience.fitting import AvailableMinimizers

Expand Down Expand Up @@ -120,6 +121,17 @@ def save_project_json(self):
except Exception as exception:
print(exception)

def load_project_json(self, path: Optional[Path] = None):
if path is None:
path = self.path_project_json

if path.exists():
with open(path, 'r') as file:
project_dict = json.load(file)
self._extract_project_dict(project_dict)
else:
print(f'ERROR: File {path} does not exist')

def _construct_project_dict(self, include_materials_not_in_model=False):
project_dict = {}
project_dict['info'] = self._info
Expand Down
17 changes: 17 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,20 @@ def test_save_project(self):

# Expect
assert project_path.exists()

def test_load_project(self):
# When
project = Project()
project._models.append(Model())
project._info['name'] = 'Test_Project'
project.save_project_json()

global_object.map._clear()
new_project = Project()

# Then
new_project.load_project_json(new_project._current_path / 'Test_Project' / 'project.json')

# Expect
assert len(new_project._models) == 1
assert new_project._info['name'] == 'Test_Project'

0 comments on commit 4836abf

Please sign in to comment.