def setUp(self): install_sample_data() self.dir = tempfile.mkdtemp('.daily_edition') self.cache_dir = os.path.join(self.dir, 'cache') self.output_dir = os.path.join(self.dir, 'editions') self.authors_filename = os.path.join(self.dir, 'authors.txt') self.stdout = StringIO.StringIO() self.old_stdout = publish_edition.stdout self.old_urlopen = urllib2.urlopen self.old_date = publish_edition.date self.old_datetime = publish_edition.datetime publish_edition.date = FakeDate(datetime.date(2010, 1, 1)) publish_edition.datetime = FakeDateTime(datetime.datetime(2010, 1, 1)) urllib2.urlopen = self.fake_urlopen publish_edition.set_stdout(self.stdout) os.mkdir(self.cache_dir) os.mkdir(self.output_dir) open(self.authors_filename, 'w').close()
def tearDown(self): urllib2.urlopen = self.old_urlopen publish_edition.date = self.old_date publish_edition.datetime = self.old_datetime publish_edition.set_stdout(self.old_stdout) remove_tree(self.dir)