Skip to content

Commit

Permalink
second refactoring of resume logic test #2
Browse files Browse the repository at this point in the history
  • Loading branch information
lirazsiri committed Aug 8, 2012
1 parent f7b9006 commit b0d0a20
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tests/resume.py
Expand Up @@ -12,14 +12,20 @@
class Error(Exception): class Error(Exception):
pass pass


def session_load(): class Session:
return simplejson.loads(file(SESSION_FILE).read()) SESSION_FILE = '/tmp/session'


def session_save(conf): @classmethod
file(SESSION_FILE, "w").write(simplejson.dumps(conf)) def load(cls):
return simplejson.loads(file(cls.SESSION_FILE).read())


def session_remove(): @classmethod
os.remove(SESSION_FILE) def save(cls, conf):
file(cls.SESSION_FILE, "w").write(simplejson.dumps(conf))

@classmethod
def remove(cls):
os.remove(cls.SESSION_FILE)


def main(): def main():
try: try:
Expand All @@ -36,8 +42,7 @@ def main():
opt_resume = True opt_resume = True


try: try:
prev_conf = session_load() prev_conf = Session.load()

except: except:
prev_conf = None prev_conf = None


Expand All @@ -61,9 +66,9 @@ def main():
print "conf: " + `conf` print "conf: " + `conf`
print "opt_resume = " + `opt_resume` print "opt_resume = " + `opt_resume`


session_save(conf) Session.save(conf)
time.sleep(3) time.sleep(3)
session_remove() Session.remove()


if __name__ == "__main__": if __name__ == "__main__":
main() main()

0 comments on commit b0d0a20

Please sign in to comment.