samila/test/warning_test.py

24 wiersze
912 B
Python
Czysty Zwykły widok Historia

2021-10-22 09:29:03 +00:00
# -*- coding: utf-8 -*-
"""
2021-10-22 10:03:10 +00:00
>>> import os
2021-11-02 20:21:37 +00:00
>>> import json
2021-10-22 09:29:03 +00:00
>>> from samila import *
>>> from pytest import warns
2021-10-22 10:52:45 +00:00
>>> with warns(RuntimeWarning, match="Neither function nor data is provided."):
2021-10-22 09:29:03 +00:00
... g = GenerativeImage()
2021-10-22 10:03:10 +00:00
>>> g = GenerativeImage(lambda x,y: 0, lambda x,y: 0)
2021-10-22 10:30:55 +00:00
>>> g.generate(step=0.1)
2021-10-22 10:52:45 +00:00
>>> result = g.save_data()
2021-10-23 18:30:25 +00:00
>>> with warns(RuntimeWarning, match="Just data is provided, generate method is not available in this mode."):
2021-10-22 10:40:00 +00:00
... g_ = GenerativeImage(data=open('data.json', 'r'))
>>> g_.data1 == g.data1
2021-10-22 10:52:45 +00:00
True
2021-10-22 10:40:00 +00:00
>>> g_.data2 == g.data2
2021-10-22 10:52:45 +00:00
True
2021-11-02 20:21:37 +00:00
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], 'matplotlib_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) is different from yours, plots may be different."):
2021-11-02 20:21:37 +00:00
... g = GenerativeImage(lambda x,y: 0, lambda x,y: 0, data=open('data.json', 'r'))
2021-10-22 10:03:10 +00:00
>>> os.remove('data.json')
2021-10-22 10:18:49 +00:00
"""