# -*- coding: utf-8 -*-
u"""Demonstrates RadiaSoft style testing.

:copyright: Copyright (c) 2016 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function
import pytest
from pykern import pkexample


def test_ema_compute():
    ema = pkexample.EMA(4)
    ema.compute(20.)
    assert 16. == ema.compute(10.), \
        'Adding a value to the series changes the average'

def test_ema_init():
    assert 5.0 == pkexample.EMA(1).compute(5.), \
        'First values sets initial average'


def test_ema_init_deviance():
    with pytest.raises(AssertionError) as e:
        pkexample.EMA(0)
    assert 'must be greater' in str(e.value)

@@ -60,16 +60,957 @@
 sting.%0A%0A
+Some Rules:%0A    We use  %60pytest %3Chttp://pytest.org%3E%60_ for unit testing.%0A%0A    1. Terminology: a %22test%22 is the file. Functions that%0A       begin with %60%60test_%60%60 are cases.%0A    #. Test cases should be simple and test only one behavior%0A    #. Assertions messages should be informative, including%0A       values that are not in the assertion comparison itself.%0A    #. Use pytest fixtures for setup/teardown. See%0A       %60yield fixtures %3Chttp://doc.pytest.org/en/latest/yieldfixture.html%3E%60_%0A       for a way to setup/teardown each test.%0A    #. Use :func:%60pykern.pkunit.save_chdir_work%60 to get automatic%0A       cleanup of files at start of test. The work dir stays%0A       around after the test runs, which helps debugging.%0A    #. Avoid global imports, even of the module under test.%0A       The pytest %22collector%22 imports all tests files into a%0A       single process so you want this to go fast and not%0A       to initialize modules during collection.%0A%0A
 :copyrig
@@ -1210,16 +1210,45 @@
  pytest%0A
+%0Adef test_ema_compute():%0A    
 from pyk
@@ -1272,34 +1272,8 @@
 ple%0A
-%0A%0Adef test_ema_compute():%0A
     
@@ -1414,16 +1414,17 @@
 erage'%0A%0A
+%0A
 def test
@@ -1432,24 +1432,57 @@
 ema_init():%0A
+    from pykern import pkexample%0A
     assert 5
@@ -1591,24 +1591,57 @@
 deviance():%0A
+    from pykern import pkexample%0A
     with pyt

document some test rules, especially due to radiasoft/sirepo#242