def test_subscribe_bad_atom():
    # setup
    setup(store)
    empty = Tiddler("bags/osmosoft_private/bad", "subscriptions.daily")
    empty.text = """[email protected]
[email protected]
"""
    twhost = environ["tiddlyweb.config"]["server_host"]["host"]
    expected = (
        u"""note you can subscribe to this feed via atom feed <%s/test/bags/osmosoft_private/bad.atom>

one <two>


Saint_Barth\xe9lemy <three>


"""
        % twhost
    )

    # run
    email = mailer.make_digest_email(
        empty, environ
    )  # now since there was no changes to the store you would expect no email

    # verify
    assert email["body"] == expected
def test_view():
    """
    test a request for viewing a single tiddler
    """
    #setup
    setup(store)
    tiddler = Tiddler('GettingStarted', 'jon_private')
    tiddler.text = 'the cat jumped over the moon'
    tiddler.tags = ['hello', 'world']
    store.put(tiddler)

    #run
    email = mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'GettingStarted',
        'body': ''
    })

    #verify
    assert email == {
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'GettingStarted',
        'body': 'the cat jumped over the moon'
    }
def test_view_tiddlers():
    """
    test a request for viewing all tiddlers in a bag
    """
    #setup
    setup(store)
    tiddler = Tiddler('one', 'jon_private')
    store.put(tiddler)
    tiddler = Tiddler('two', 'jon_private')
    store.put(tiddler)
    tiddler = Tiddler('three', 'jon_private')
    store.put(tiddler)
    tiddler = Tiddler('four', 'jon_private')
    store.put(tiddler)

    #run
    email = mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': '',
        'body': ''
    })

    #verify
    assert email['to'] == '*****@*****.**'
    body = email['body'].splitlines()
    assert body.pop(0) == 'The following tiddlers are in jon.tiddlyspace.com:'
    assert len(body) == 4
    for tiddler_name in body: 
        assert tiddler_name in ['one', 'two', 'three', 'four']
def test_post_existing():
    """
    testing posting an existing tiddler to check that it is overwritten
    """
    #setup
    setup(store)
    tiddler = Tiddler('i exist','jon_private')
    tiddler.fields['geo.lat'] = '20'
    tiddler.fields['geo.long'] = '2'
    tiddler.text = 'data'
    tiddler.tags = ['a', 'b']
    store.put(tiddler)
    
    #run
    mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'i exist',
        'body': 'wipeout'
    })

    #verify  
    tiddler = store.get(Tiddler('i exist', 'jon_private'))
    assert tiddler.text == 'wipeout'
    assert tiddler.fields.get('geo.lat') == None
def test_post_new():
    """
    testing posting a new tiddler to tiddlyweb via email
    and that a reply to the response doesn't overwrite that tiddler
    """
    #setup
    setup(store)

    #run
    email = mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'Jons brand spanking new tiddler',
        'body': 'I love email tiddlyweb'
    })

    #verify  
    try:
        tiddler = Tiddler('Jons brand spanking new tiddler', 'jon_private')
        tiddler = store.get(tiddler)
    except NoTiddlerError:
        raise AssertionError('Tiddler has not been put into store')
    
    assert tiddler.text == 'I love email tiddlyweb'
    assert tiddler.tags == []
    
    assert email['from'] == '*****@*****.**'
    assert email['to'] == '*****@*****.**'
    assert email['subject'] == 'Jons brand spanking new tiddler'
    
    #check a reply doesn't overwrite the tiddler
    reply = {
        'subject': 'RE: Jons brand spanking new tiddler',
        'from': '*****@*****.**',
        'to': '*****@*****.**',
        'body': 'thanks tiddlyweb!'
    }
    
    #run
    email = mailer.handle_email(reply)
    
    #verify
    tiddler = Tiddler('Jons brand spanking new tiddler', 'jon_private')
    tiddler = store.get(tiddler)
    
    assert tiddler.text == 'I love email tiddlyweb'
    
    assert email == {
        'body': 'I love email tiddlyweb',
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'Jons brand spanking new tiddler'
    }
Beispiel #6
0
def execute(env_name, model_path, epochs, dump_path, include):
    with Display(visible=False) as disp:
        env, policy = setup(env_name, model_path, dump_path, include)
        with st.empty():
            for epoch in range(1, epochs + 1):
                for img in rollout(env, policy):
                    st.image(img, caption=f"Epoch {epoch}")
Beispiel #7
0
def setup():
    # Get the process.py from src/python-sitelib (incompatibilities
    # introduced in the new src/python-sitelib/process.py for Komodo
    # 4.3.0).
    pylib_dir = join(dirname(dirname(abspath(__file__))), "src",
                     "python-sitelib")
    sys.path.insert(0, pylib_dir)
    try:
        import process
    finally:
        del sys.path[0]

    codeintel_test_dir = join(dirname(dirname(abspath(__file__))), "src",
                              "codeintel", "test2")
    sys.path.insert(0, codeintel_test_dir)
    try:
        import test
        test.setup()
    except ImportError, ex:
        pass  # Don't bork if don't have full codeintel build.
Beispiel #8
0
def setup():
    # Get the process.py from src/python-sitelib (incompatibilities
    # introduced in the new src/python-sitelib/process.py for Komodo
    # 4.3.0).
    pylib_dir = join(dirname(dirname(abspath(__file__))),
                     "src", "python-sitelib")
    sys.path.insert(0, pylib_dir)
    try:
        import process
    finally:
        del sys.path[0]
    
    codeintel_test_dir = join(dirname(dirname(abspath(__file__))),
                              "src", "codeintel", "test2")
    sys.path.insert(0, codeintel_test_dir)
    try:
        import test
        test.setup()
    except ImportError, ex:
        pass  # Don't bork if don't have full codeintel build.
def test_posting_of_tags():
    """
    overwriting a tiddler with tags with a tiddler with
    a different set of tags via email
    """
    #setup
    setup(store)
    tiddler = Tiddler('Hey there', 'ben_private')
    tiddler.tags = ['rainbows', 'colourful']
    store.put(tiddler)

    #run
    mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'Hey there',
        'body': 'tiddler text'
    })

    #verify
    tiddler = Tiddler('Hey there', 'ben_private')
    tiddler = store.get(tiddler)
    assert tiddler.tags == ['foo', 'bar', 'baz']
def test_view_reply():
    """
    test a request for viewing based on a reply to a previous response
    ie - the subject has an RE: in it.
    """
    #setup
    setup(store)
    tiddler = Tiddler('GettingStarted', 'ben_private')
    tiddler.text = 'The quick brown fox jumped over the lazy dog'
    store.put(tiddler)
    
    #run
    email = mailer.handle_email({
        'to': '*****@*****.**',
        'from': '*****@*****.**',
        'subject': 'RE: GettingStarted',
        'body': ''
    })
    
    #verify
    assert email['to'] == '*****@*****.**'
    assert email['from'] == '*****@*****.**'
    assert email['subject'] == 'GettingStarted'
    assert email['body'] == 'The quick brown fox jumped over the lazy dog'
Beispiel #11
0
def test_compute_productivity_index():

    from test import setup as setup

    parameters = setup()

    parameters['wells'] = {
        'rate': {
            'locations': [(0.0, 1.0)],
            'values': [1000],
            'radii': [0.25]
        },
        'bhp': {
            'locations': [(6250.0, 1.0)],
            'values': [800],
            'radii': [0.25]
        }
    }

    parameters['reservoir'] = {
        'permeability': 50,  #mD
        'porosity': 0.2,
        'length': 10000,  #ft
        'height': 2500,  #ft
        'depth': 80  #ft
    }

    parameters['boundary conditions']['left']['type'] = 'prescribed flux'
    parameters['boundary conditions']['left']['value'] = 0.0
    parameters['boundary conditions']['right']['type'] = 'prescribed pressure'
    parameters['boundary conditions']['right']['value'] = 2000.0

    problem = TwoDimReservoir(parameters)

    np.testing.assert_allclose(problem.compute_productivity_index('bhp'),
                               3310.9,
                               atol=0.5)

    return
def test_subscribe():
    # setup
    setup(store)
    empty = Tiddler("bags/osmosoft_private/empty", "subscriptions.daily")
    empty.text = """
[email protected]
[email protected]
"""
    store.put(empty)

    # run
    email = mailer.handle_email(
        {"to": "*****@*****.**", "from": "*****@*****.**", "subject": "", "body": ""}
    )

    # verify
    tid = store.get(Tiddler("bags/osmosoft_private/tiddlers", "subscriptions.daily"))
    assert tid.text == "*****@*****.**"

    email = mailer.handle_email(
        {"to": "*****@*****.**", "from": "*****@*****.**", "subject": "", "body": ""}
    )
    email = mailer.handle_email(
        {"to": "*****@*****.**", "from": "*****@*****.**", "subject": "", "body": ""}
    )

    tid = store.get(Tiddler("bags/osmosoft_private/tiddlers", "subscriptions.daily"))
    lines = tid.text.splitlines()
    assert len(lines) == 3
    for i in [u"*****@*****.**", u"*****@*****.**", u"*****@*****.**"]:
        assert i in lines

    email = mailer.handle_email(
        {"to": "*****@*****.**", "from": "*****@*****.**", "subject": "", "body": ""}
    )
    email = mailer.handle_email(
        {"to": "*****@*****.**", "from": "*****@*****.**", "subject": "", "body": ""}
    )
    tid = store.get(Tiddler("bags/osmosoft_private/tiddlers", "subscriptions.daily"))
    lines = tid.text.splitlines()
    email = mailer.make_digest_email(tid, environ)
    bcc = email["bcc"]
    assert len(bcc) == 2
    assert len(lines) == 2
    assert email["from"] == "*****@*****.**"
    for i in [u"*****@*****.**", u"*****@*****.**"]:
        assert i in lines
        assert i in bcc
    twhost = environ["tiddlyweb.config"]["server_host"]["host"]
    expected = (
        u"""note you can subscribe to this feed via atom feed <%s/test/bags/osmosoft_private/tiddlers.atom>

The meaning of life <http://monty.tiddlyspace.com/meaninglife>
The knights that go..

Life of Brian <http://monty.tiddlyspace.com/lifeofbrian>
He's been a very naughty boy.

"""
        % twhost
    )

    print "###########"
    assert email["body"] == expected
    expected = (
        u'<html><div>note you can <a href="%s/test/bags/osmosoft_private/tiddlers.atom">subscribe to this feed via atom feed</a></div><div><a href="http://monty.tiddlyspace.com/meaninglife"><h1>The meaning of life</h1></a>The knights that go..</div><div><a href="http://monty.tiddlyspace.com/lifeofbrian"><h1>Life of Brian</h1></a>He\'s been a very naughty boy.</div></html>'
        % twhost
    )
    assert email["bodyhtml"] == expected
    assert email["subject"] == u"Email Digest: Tiddlers in bag for testing purposes"
    tid = store.get(tid)
    assert "last_generated" in tid.fields

    global totalsent
    totalsent = 0

    def new_sendmail(email):
        global totalsent
        print "sending as part of make_digest_email test"
        totalsent += 1

    dummymailer.send_email = new_sendmail
    dummymailer.make_digest(["subscriptions.daily"])

    assert (
        totalsent is 1
    )  # one email is sent with all the email addresses blind carbon copied. osmosoft_private/empty is empty so wont cause emails

    tid = store.get(Tiddler("bags/osmosoft_private/empty", "subscriptions.daily"))
    email = dummymailer.make_digest_email(
        tid, environ
    )  # now since there was no changes to the store you would expect no email
    assert email is False
    assert "last_generated" not in tid.fields  # havent sent one yet