import os
import shutil

import pytest

from LiSE.engine import Engine
from LiSE.examples.kobold import inittest



def test_keyframe_load_init(tempdir):
    """Can load a keyframe at start of branch, including locations"""
    eng = Engine(tempdir)
    inittest(eng)
    eng.branch = 'new'
    eng.snap_keyframe()
    eng.close()
    eng = Engine(tempdir)
    assert 'kobold' in eng.character['physical'].thing
    assert (0, 0) in eng.character['physical'].place
    assert (0, 1) in eng.character['physical'].portal[0, 0]
    eng.close()


def test_multi_keyframe(tempdir):
    eng = Engine(tempdir)
    inittest(eng, kobold_pos=(9, 9))
    eng.snap_keyframe()
    tick0 = eng.tick
    eng.turn = 1
    eng.character['physical'].thing['kobold']['location'] = (3, 3)
    eng.snap_keyframe()
    tick1 = eng.tick
    eng.close()
    eng = Engine(tempdir)
    eng._load_at('trunk', 0, tick0+1)
    assert eng._things_cache.keyframe['physical']['trunk'][0][tick0]\
           != eng._things_cache.keyframe['physical']['trunk'][1][tick1]

import os
import shutil

import pytest

from LiSE.engine import Engine
from LiSE.examples.kobold import inittest



def test_keyframe_load_init(tempdir):
    """Can load a keyframe at start of branch, including locations"""
    eng = Engine(tempdir)
    inittest(eng)
    eng.branch = 'new'
    eng.snap_keyframe()
    eng.close()
    eng = Engine(tempdir)
    assert 'kobold' in eng.character['physical'].thing
    assert (0, 0) in eng.character['physical'].place
    assert (0, 1) in eng.character['physical'].portal[0, 0]
    eng.close()


def test_multi_keyframe(tempdir):
    eng = Engine(tempdir)
    inittest(eng)
    eng.snap_keyframe()
    tick0 = eng.tick
    eng.turn = 1
    del eng.character['physical'].place[3, 3]
    eng.snap_keyframe()
    tick1 = eng.tick
    eng.close()
    eng = Engine(tempdir)
    eng._load_at('trunk', 0, tick0+1)
    assert eng._nodes_cache.keyframe['physical', ]['trunk'][0][tick0]\
           != eng._nodes_cache.keyframe['physical', ]['trunk'][1][tick1]

Make test_multi_keyframe demonstrate what it's supposed to
Make test_multi_keyframe demonstrate what it's supposed to

I was testing a cache that wasn't behaving correctly for
unrelated reasons.

  import os
  import shutil
  
  import pytest
  
  from LiSE.engine import Engine
  from LiSE.examples.kobold import inittest
  
  
  
  def test_keyframe_load_init(tempdir):
      """Can load a keyframe at start of branch, including locations"""
      eng = Engine(tempdir)
      inittest(eng)
      eng.branch = 'new'
      eng.snap_keyframe()
      eng.close()
      eng = Engine(tempdir)
      assert 'kobold' in eng.character['physical'].thing
      assert (0, 0) in eng.character['physical'].place
      assert (0, 1) in eng.character['physical'].portal[0, 0]
      eng.close()
  
  
  def test_multi_keyframe(tempdir):
      eng = Engine(tempdir)
-     inittest(eng, kobold_pos=(9, 9))
+     inittest(eng)
      eng.snap_keyframe()
      tick0 = eng.tick
      eng.turn = 1
-     eng.character['physical'].thing['kobold']['location'] = (3, 3)
+     del eng.character['physical'].place[3, 3]
      eng.snap_keyframe()
      tick1 = eng.tick
      eng.close()
      eng = Engine(tempdir)
      eng._load_at('trunk', 0, tick0+1)
-     assert eng._things_cache.keyframe['physical']['trunk'][0][tick0]\
+     assert eng._nodes_cache.keyframe['physical', ]['trunk'][0][tick0]\
-            != eng._things_cache.keyframe['physical']['trunk'][1][tick1]
+            != eng._nodes_cache.keyframe['physical', ]['trunk'][1][tick1]
  
Make test_multi_keyframe demonstrate what it's supposed to
## Code Before:
import os
import shutil

import pytest

from LiSE.engine import Engine
from LiSE.examples.kobold import inittest



def test_keyframe_load_init(tempdir):
    """Can load a keyframe at start of branch, including locations"""
    eng = Engine(tempdir)
    inittest(eng)
    eng.branch = 'new'
    eng.snap_keyframe()
    eng.close()
    eng = Engine(tempdir)
    assert 'kobold' in eng.character['physical'].thing
    assert (0, 0) in eng.character['physical'].place
    assert (0, 1) in eng.character['physical'].portal[0, 0]
    eng.close()


def test_multi_keyframe(tempdir):
    eng = Engine(tempdir)
    inittest(eng, kobold_pos=(9, 9))
    eng.snap_keyframe()
    tick0 = eng.tick
    eng.turn = 1
    eng.character['physical'].thing['kobold']['location'] = (3, 3)
    eng.snap_keyframe()
    tick1 = eng.tick
    eng.close()
    eng = Engine(tempdir)
    eng._load_at('trunk', 0, tick0+1)
    assert eng._things_cache.keyframe['physical']['trunk'][0][tick0]\
           != eng._things_cache.keyframe['physical']['trunk'][1][tick1]

## Instruction:
Make test_multi_keyframe demonstrate what it's supposed to
## Code After:
import os
import shutil

import pytest

from LiSE.engine import Engine
from LiSE.examples.kobold import inittest



def test_keyframe_load_init(tempdir):
    """Can load a keyframe at start of branch, including locations"""
    eng = Engine(tempdir)
    inittest(eng)
    eng.branch = 'new'
    eng.snap_keyframe()
    eng.close()
    eng = Engine(tempdir)
    assert 'kobold' in eng.character['physical'].thing
    assert (0, 0) in eng.character['physical'].place
    assert (0, 1) in eng.character['physical'].portal[0, 0]
    eng.close()


def test_multi_keyframe(tempdir):
    eng = Engine(tempdir)
    inittest(eng)
    eng.snap_keyframe()
    tick0 = eng.tick
    eng.turn = 1
    del eng.character['physical'].place[3, 3]
    eng.snap_keyframe()
    tick1 = eng.tick
    eng.close()
    eng = Engine(tempdir)
    eng._load_at('trunk', 0, tick0+1)
    assert eng._nodes_cache.keyframe['physical', ]['trunk'][0][tick0]\
           != eng._nodes_cache.keyframe['physical', ]['trunk'][1][tick1]
