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 sepandhaghighi/data
Data Save and Load Structure
- Loading branch information
Showing
10 changed files
with
153 additions
and
3 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
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,2 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Samila errors.""" | ||
|
||
|
||
class samilaDataError(Exception): | ||
"""Data error class.""" | ||
|
||
pass | ||
|
||
|
||
class samilaGenerateError(Exception): | ||
"""Generate error class.""" | ||
|
||
pass |
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
>>> from samila import * | ||
>>> import os | ||
>>> from pytest import warns | ||
>>> g = GenerativeImage(data="data.json") | ||
Traceback (most recent call last): | ||
... | ||
samila.errors.samilaDataError: Provided data file is not supported. It should be either file or io.IOBase. | ||
>>> with open('data.json', 'w') as fp: | ||
... result = fp.write('test') | ||
>>> g = GenerativeImage(data=open("data.json", 'r')) | ||
Traceback (most recent call last): | ||
... | ||
samila.errors.samilaDataError: Provided data format is wrong. It should be in JSON format including data1 and data2 fields. | ||
>>> g = GenerativeImage(lambda x,y: 0, lambda x,y: 0) | ||
>>> g.generate(step=0.1) | ||
>>> result = g.save_data('data.json') | ||
>>> with warns(RuntimeWarning, match="Just data is provided, generate method is not available in this mode."): | ||
... g = GenerativeImage(data=open('data.json', 'r')) | ||
>>> g.generate() | ||
Traceback (most recent call last): | ||
... | ||
samila.errors.samilaGenerateError: At least one of the given functions are None. | ||
>>> os.remove('data.json') | ||
""" |
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,18 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
>>> import os | ||
>>> from samila import * | ||
>>> from pytest import warns | ||
>>> with warns(RuntimeWarning, match="Neither function nor data is provided."): | ||
... g = GenerativeImage() | ||
>>> g = GenerativeImage(lambda x,y: 0, lambda x,y: 0) | ||
>>> g.generate(step=0.1) | ||
>>> result = g.save_data() | ||
>>> with warns(RuntimeWarning, match="Just data is provided, generate method is not available in this mode."): | ||
... g_ = GenerativeImage(data=open('data.json', 'r')) | ||
>>> g_.data1 == g.data1 | ||
True | ||
>>> g_.data2 == g.data2 | ||
True | ||
>>> os.remove('data.json') | ||
""" |