Vous avez déjà un morceau exemple de code (Python) pour vérifier si un répertoire a changé:Précision de mtime stat dans Windows
Mais unittest d'accompagnement échoue au hasard à moins ajouter au moins un second sommeil 2:
import unittest
import project_creator
import os
import time
class tests(unittest.TestCase):
def setUp(self):
os.makedirs('autotest')
f = open(os.path.join('autotest', 'new_file.txt'), 'w')
f.write('New file')
def tearDown(self):
os.unlink(os.path.join('autotest', 'new_file.txt'))
os.rmdir('autotest')
def test_amend_file(self):
changed = project_creator.watch('autotest', {})
time.sleep(2)
f = open(os.path.join('autotest', 'new_file.txt'), 'a')
f.write('\nA change!')
f.close()
changed = project_creator.watch('autotest', changed[0])
self.assertEqual(changed[1], [os.path.abspath(os.path.join('autotest', 'new_file.txt'))])
if __name__ == '__main__':
unittest.main()
Est-ce que stat est vraiment limité à une précision inférieure à 1 seconde? (Edit: apparemment, avec FAT) Existe-t-il un moyen (multi-plateforme) de détecter des changements plus rapides?
Voir http://stackoverflow.com/questions/943503/python-getting-file-modification-times-with-greater-resolution-than-a-second. – unwind
Merci, ça répond à la première question (mon google-fu manquait évidemment quand j'ai cherché plus tôt). Je suis toujours intéressé par les méthodes alternatives (s'il y en a). – mavnn