-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path12-switcher-session.py
More file actions
executable file
·65 lines (50 loc) · 2.1 KB
/
12-switcher-session.py
File metadata and controls
executable file
·65 lines (50 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
import pyquid
import os
sw = pyquid.Switcher('session_test', debug=True)
assert hasattr(sw, 'session')
# Save current session state to a new file under the directory
# defined by the `session.path` configuration key:
# ```json
# {
# "session": {
# "path": "path/to/session_directory"
# }
# }
# ```
s1_filepath = sw.session.save_as("session1")
s2_filepath = sw.session.save_as("session2.json")
assert isinstance(s1_filepath, str) and os.path.exists(s1_filepath)
assert isinstance(s2_filepath, str) and os.path.exists(s2_filepath)
# Copy an existing session file to a new file
assert sw.session.copy("session2", "session3.json") is True
# list existing session files
session_files = sw.session.list()
assert isinstance(session_files, list) and len(session_files) >= 3
# load session file, parse it and load it into switcher's current state
assert sw.session.load("session1")
assert sw.session.load("session2.json")
# remove test session files
assert sw.session.remove("session1")
assert sw.session.remove("session2.json")
assert sw.session.remove("session3")
sw2 = pyquid.Switcher('session_test', debug=True)
assert (sw2.session != sw.session)
# check that session methods are restricted to the session files directory (XDG_CONFIG_HOME by default)
s3_filepath = sw.session.save_as('/../sneaky/path/to/s3.json')
assert isinstance(s3_filepath, str) and os.path.exists(s3_filepath)
assert "s3.json" in sw.session.list()
assert sw.session.copy('s3', '../s4')
assert "s4.json" in sw.session.list()
assert sw.session.remove('s3')
assert sw.session.load('../s4')
assert sw.session.remove('s4')
exit(0)