def test_previous_file_doesnt_autofill(self): config = self.default_config.copy() tmp_entries_dir = tempfile.mkdtemp() os.remove(self.entries_file) self.entries_file = os.path.join(tmp_entries_dir, '%m_%Y.txt') config['default']['file'] = self.entries_file with freeze_time('2014-01-21'): self.write_entries("""20/01/2014 alias_1 2 hello world 21/01/2014 alias_1 1 foo bar """) with freeze_time('2014-02-21'): self.write_entries("""20/02/2014 alias_1 2 hello world """) self.run_command('edit', args=['1'], config_options=config) with freeze_time('2014-01-21'): with open(expand_date(self.entries_file), 'r') as f: lines = f.readlines() self.assertNotIn('21/02/2014\n', lines)
def test_previous_file_doesnt_autofill(self): tmp_entries_dir = tempfile.mkdtemp() os.remove(self.entries_file) self.entries_file = os.path.join(tmp_entries_dir, '%m_%Y.txt') with self.settings({'default': {'file': self.entries_file}}): with freeze_time('2014-01-21'): self.write_entries("""20/01/2014 alias_1 2 hello world 21/01/2014 alias_1 1 foo bar """) with freeze_time('2014-02-21'): self.write_entries("""20/02/2014 alias_1 2 hello world """) self.run_command('edit', args=['1']) with freeze_time('2014-01-21'): with open(expand_date(self.entries_file), 'r') as f: lines = f.readlines() self.assertNotIn('21/02/2014\n', lines)
def test_prefill_entries_add_to_bottom(self): config = self.default_config.copy() tmp_entries_dir = tempfile.mkdtemp() os.remove(self.entries_file) self.entries_file = os.path.join(tmp_entries_dir, '%m_%Y.txt') config['default']['file'] = self.entries_file with freeze_time('2014-01-21'): self.write_entries("""20/01/2014 alias_1 2 hello world 21/01/2014 alias_1 1 foo bar """) with freeze_time('2014-02-21'): self.write_entries("""20/02/2014 alias_1 2 hello world """) self.run_command('edit', config_options=config) with open(expand_date(self.entries_file), 'r') as f: lines = f.readlines() self.assertEqual('20/02/2014\n', lines[0]) self.assertEqual('21/02/2014\n', lines[3])
def test_prefill_entries_add_to_bottom(self): tmp_entries_dir = tempfile.mkdtemp() os.remove(self.entries_file) self.entries_file = os.path.join(tmp_entries_dir, '%m_%Y.txt') with self.settings({'default': {'file': self.entries_file}}): with freeze_time('2014-01-21'): self.write_entries("""20/01/2014 alias_1 2 hello world 21/01/2014 alias_1 1 foo bar """) with freeze_time('2014-02-21'): self.write_entries("""20/02/2014 alias_1 2 hello world """) self.run_command('edit') with open(expand_date(self.entries_file), 'r') as f: lines = f.readlines() self.assertEqual('20/02/2014\n', lines[0]) self.assertEqual('21/02/2014\n', lines[3])
def tearDown(self): backends_registry._entry_points = self.backends_original_entry_points entries_file = expand_date(self.entries_file) os.remove(self.config_file) if os.path.exists(entries_file): os.remove(entries_file) shutil.rmtree(self.taxi_dir)
def read_entries(self): with codecs.open(expand_date(self.entries_file), 'r', 'utf-8') as f: contents = f.read() return contents
def write_entries(self, contents): with codecs.open(expand_date(self.entries_file), 'a', 'utf-8') as f: f.write(contents)
def expand(self, date): return self.tmpdir.join(expand_date(self.pattern, date))