Esempio n. 1
0
	def test_add_image_to_shared_folder(self):
		'''
		monitor file contents of a directory add a file and assert that in a call to new_image_paths = m.get_new_image_paths() new_image_paths contains the new file
		'''
		os.mkdir('tmp')
		m = MonitorDirectory('tmp', image_extension='.tmp')

		# create dummy file
		open('tmp/tmp.tmp', 'w').close()

		new_image_paths = m.get_new_image_paths()

		logger.info(new_image_paths)

		self.assertTrue('tmp.tmp' in new_image_paths)

		os.remove('tmp/tmp.tmp')
		os.rmdir('tmp')
Esempio n. 2
0
	def test_update_image_paths(self):
		os.mkdir('tmp')
		open('tmp/1.tmp', 'w').close()

		m = MonitorDirectory('tmp', image_extension='.tmp')
		open('tmp/2.tmp', 'w').close()
		open('tmp/3.tmp', 'w').close()
		new_image_paths = m.get_new_image_paths()
		m.update(new_image_paths)

		self.assertEquals(m.image_paths, set(['1.tmp', '2.tmp', '3.tmp']))

		new_image_paths = m.get_new_image_paths()

		self.assertTrue(len(new_image_paths)==0)

		[os.remove(i) for i in iglob('tmp/*.tmp')]
		os.rmdir('tmp')
Esempio n. 3
0
	def test_get_directory_contents(self):
		'''
		make sure m.get_directory_contents contains all files with image_extension
		'''
		try:
			os.mkdir('tmp')

			# create dummy file
			open('tmp/tmp.tmp', 'w').close()

			m = MonitorDirectory('tmp', image_extension='.tmp')
			directory_contents = m.get_directory_contents()
			for i in directory_contents:
				logger.info('directory content %s' % i)

			self.assertEquals(directory_contents, set(['tmp.tmp']))
		except:
			pass
		finally:
			[os.remove(i) for i in iglob('tmp/*.tmp')]
			os.rmdir('tmp')