12
12
import io
13
13
import itertools
14
14
import json
15
- import math
16
15
import os
17
16
import time
18
17
import unittest
@@ -1171,15 +1170,21 @@ def test_removetree_root(self):
1171
1170
1172
1171
def test_setinfo (self ):
1173
1172
self .fs .create ("birthday.txt" )
1174
- now = math . floor ( time .time () )
1173
+ now = time .time ()
1175
1174
1176
1175
change_info = {"details" : {"accessed" : now + 60 , "modified" : now + 60 * 60 }}
1177
1176
self .fs .setinfo ("birthday.txt" , change_info )
1178
- new_info = self .fs .getinfo ("birthday.txt" , namespaces = ["details" ]).raw
1179
- if "accessed" in new_info .get ("_write" , []):
1180
- self .assertEqual (new_info ["details" ]["accessed" ], now + 60 )
1181
- if "modified" in new_info .get ("_write" , []):
1182
- self .assertEqual (new_info ["details" ]["modified" ], now + 60 * 60 )
1177
+ new_info = self .fs .getinfo ("birthday.txt" , namespaces = ["details" ])
1178
+ can_write_acccess = new_info .is_writeable ("details" , "accessed" )
1179
+ can_write_modified = new_info .is_writeable ("details" , "modified" )
1180
+ if can_write_acccess :
1181
+ self .assertAlmostEqual (
1182
+ new_info .get ("details" , "accessed" ), now + 60 , places = 4
1183
+ )
1184
+ if can_write_modified :
1185
+ self .assertAlmostEqual (
1186
+ new_info .get ("details" , "modified" ), now + 60 * 60 , places = 4
1187
+ )
1183
1188
1184
1189
with self .assertRaises (errors .ResourceNotFound ):
1185
1190
self .fs .setinfo ("nothing" , {})
@@ -1188,10 +1193,11 @@ def test_settimes(self):
1188
1193
self .fs .create ("birthday.txt" )
1189
1194
self .fs .settimes ("birthday.txt" , accessed = datetime (2016 , 7 , 5 ))
1190
1195
info = self .fs .getinfo ("birthday.txt" , namespaces = ["details" ])
1191
- writeable = info .get ("details" , "_write" , [])
1192
- if "accessed" in writeable :
1196
+ can_write_acccess = info .is_writeable ("details" , "accessed" )
1197
+ can_write_modified = info .is_writeable ("details" , "modified" )
1198
+ if can_write_acccess :
1193
1199
self .assertEqual (info .accessed , datetime (2016 , 7 , 5 , tzinfo = pytz .UTC ))
1194
- if "modified" in writeable :
1200
+ if can_write_modified :
1195
1201
self .assertEqual (info .modified , datetime (2016 , 7 , 5 , tzinfo = pytz .UTC ))
1196
1202
1197
1203
def test_touch (self ):
0 commit comments