Example #1
0
def test_cache_path_is_none(fake_server, monkeypatch):
    # currency.initialize_db() is called with :memory: when cache_path is None.
    monkeypatch.setattr(currency, 'initialize_db',
                        log_calls(currency.initialize_db))
    Application(ApplicationGUI())  # default cache_path is None
    expected = [{'path': ':memory:'}]
    eq_(currency.initialize_db.calls, expected)
Example #2
0
def test_cache_path_is_not_none(fake_server, monkeypatch, tmpdir):
    # currency.initialize_db() is called with cache_path/currency.db when cache_path is not None.
    cache_path = str(tmpdir)
    monkeypatch.setattr(currency, 'initialize_db',
                        log_calls(currency.initialize_db))
    Application(ApplicationGUI(), cache_path=cache_path)
    expected = [{'path': op.join(cache_path, 'currency.db')}]
    eq_(currency.initialize_db.calls, expected)
Example #3
0
def test_cache_path_is_none(fake_server, monkeypatch):
    # currency.initialize_db() is called with :memory: when cache_path is None.
    monkeypatch.setattr(currency, 'initialize_db', log_calls(currency.initialize_db))
    app = Application(ApplicationGUI()) # default cache_path is None
    expected = [
        {'path': ':memory:'}
    ]
    eq_(currency.initialize_db.calls, expected)
Example #4
0
 def pytest_funcarg__do_setup(self, request):
     monkeypatch = request.getfuncargvalue('monkeypatch')
     monkeypatch.setattr(hscommon.util, 'delete_if_empty',
                         log_calls(lambda path, files_to_delete=[]: None))
     # XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
     monkeypatch.setattr(app, 'delete_if_empty',
                         hscommon.util.delete_if_empty)
     self.app = TestApp().app
Example #5
0
 def test_apply_filter_calls_results_apply_filter(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, "apply_filter", log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter("foo")
     eq_(2, len(dgapp.results.apply_filter.calls))
     call = dgapp.results.apply_filter.calls[0]
     assert call["filter_str"] is None
     call = dgapp.results.apply_filter.calls[1]
     eq_("foo", call["filter_str"])
Example #6
0
def test_cache_path_is_not_none(fake_server, monkeypatch, tmpdir):
    # currency.initialize_db() is called with cache_path/currency.db when cache_path is not None.
    cache_path = str(tmpdir)
    monkeypatch.setattr(currency, 'initialize_db', log_calls(currency.initialize_db))
    app = Application(ApplicationGUI(), cache_path=cache_path)
    expected = [
        {'path': op.join(cache_path, 'currency.db')}
    ]
    eq_(currency.initialize_db.calls, expected)
Example #7
0
 def test_apply_filter_calls_results_apply_filter(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter('foo')
     eq_(2, len(dgapp.results.apply_filter.calls))
     call = dgapp.results.apply_filter.calls[0]
     assert call['filter_str'] is None
     call = dgapp.results.apply_filter.calls[1]
     eq_('foo', call['filter_str'])
Example #8
0
 def test_apply_filter_calls_results_apply_filter(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter('foo')
     eq_(2, len(dgapp.results.apply_filter.calls))
     call = dgapp.results.apply_filter.calls[0]
     assert call['filter_str'] is None
     call = dgapp.results.apply_filter.calls[1]
     eq_('foo', call['filter_str'])
Example #9
0
 def test_apply_filter_calls_results_apply_filter(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, "apply_filter",
                         log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter("foo")
     eq_(2, len(dgapp.results.apply_filter.calls))
     call = dgapp.results.apply_filter.calls[0]
     assert call["filter_str"] is None
     call = dgapp.results.apply_filter.calls[1]
     eq_("foo", call["filter_str"])
Example #10
0
 def do_setup(self, request):
     monkeypatch = request.getfixturevalue("monkeypatch")
     monkeypatch.setattr(
         hscommon.util,
         "delete_if_empty",
         log_calls(lambda path, files_to_delete=[]: None),
     )
     # XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
     monkeypatch.setattr(app, "delete_if_empty",
                         hscommon.util.delete_if_empty)
     self.app = TestApp().app
Example #11
0
 def test_get_mtime_cooldown(self, tmpdir, monkeypatch):
     monkeypatch.setattr(os, 'stat', log_calls(os.stat))
     tmppath = str(tmpdir)
     d = phys.Directory(None, tmppath)  #empty
     d[:]
     len(d)
     'foo' in d
     eq_(1, len(os.stat.calls))
     time.sleep(1)
     # Create a new file
     open(op.join(tmppath, 'somefile'), 'w').close()
     assert 'somefile' in d
Example #12
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, "warning", log_calls(lambda msg: None))
     assert not app.rename_selected("renamed")
     msg = logging.warning.calls[0]["msg"]
     eq_("dupeGuru Warning: list index out of range", msg)
     names = [p.name for p in self.p.listdir()]
     assert "renamed" not in names
     assert "foo bar 2" in names
     eq_(g.dupes[0].name, "foo bar 2")
Example #13
0
 def test_get_mtime_cooldown(self, tmpdir, monkeypatch):
     monkeypatch.setattr(os, 'stat', log_calls(os.stat))
     tmppath = str(tmpdir)
     d = phys.Directory(None, tmppath) #empty
     d[:]
     len(d)
     'foo' in d
     eq_(1, len(os.stat.calls))
     time.sleep(1)
     # Create a new file
     open(op.join(tmppath, 'somefile'), 'w').close()
     assert 'somefile' in d
Example #14
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, "warning", log_calls(lambda msg: None))
     assert not app.rename_selected("foo bar 1")
     msg = logging.warning.calls[0]["msg"]
     assert msg.startswith("dupeGuru Warning: 'foo bar 1' already exists in")
     names = [p.name for p in self.p.listdir()]
     assert "foo bar 1" in names
     assert "foo bar 2" in names
     eq_(g.dupes[0].name, "foo bar 2")
Example #15
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('foo bar 1')
     msg = logging.warning.calls[0]['msg']
     assert msg.startswith('dupeGuru Warning: \'foo bar 1\' already exists in')
     names = io.listdir(self.p)
     assert 'foo bar 1' in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Example #16
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('renamed')
     msg = logging.warning.calls[0]['msg']
     eq_('dupeGuru Warning: list index out of range', msg)
     names = [p.name for p in self.p.listdir()]
     assert 'renamed' not in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Example #17
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, "warning", log_calls(lambda msg: None))
     assert not app.rename_selected("renamed")
     msg = logging.warning.calls[0]["msg"]
     eq_("dupeGuru Warning: list index out of range", msg)
     names = [p.name for p in self.p.listdir()]
     assert "renamed" not in names
     assert "foo bar 2" in names
     eq_(g.dupes[0].name, "foo bar 2")
Example #18
0
def test_ensures_rates(tmpdir, fake_server, monkeypatch):
    # Upon calling save and load, rates are asked for both EUR and PLN.
    app = app_entry_with_foreign_currency()
    rates_db = Currency.get_rates_db()
    monkeypatch.setattr(rates_db, 'ensure_rates', log_calls(rates_db.ensure_rates))
    filename = str(tmpdir.join('foo.xml'))
    app.doc.save_to_xml(filename)
    app.doc.load_from_xml(filename)
    calls = rates_db.ensure_rates.calls
    eq_(len(calls), 1)
    eq_(set(calls[0]['currencies']), set(['PLN', 'EUR', 'CAD']))
    eq_(calls[0]['start_date'], date(2007, 10, 1))
Example #19
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('foo bar 1')
     msg = logging.warning.calls[0]['msg']
     assert msg.startswith('dupeGuru Warning: \'foo bar 1\' already exists in')
     names = [p.name for p in self.p.listdir()]
     assert 'foo bar 1' in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Example #20
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('renamed')
     msg = logging.warning.calls[0]['msg']
     eq_('dupeGuru Warning: list index out of range', msg)
     names = [p.name for p in self.p.listdir()]
     assert 'renamed' not in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Example #21
0
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath + 'source'
     io.mkdir(sourcepath)
     io.open(sourcepath + 'myfile', 'w')
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, 'clean_empty_dirs', log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath + 'dest', 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]['path'])
Example #22
0
 def test_apply_filter_escapes_regexp(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter('()[]\\.|+?^abc')
     call = dgapp.results.apply_filter.calls[1]
     eq_('\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc', call['filter_str'])
     dgapp.apply_filter('(*)') # In "simple mode", we want the * to behave as a wilcard
     call = dgapp.results.apply_filter.calls[3]
     eq_('\(.*\)', call['filter_str'])
     dgapp.options['escape_filter_regexp'] = False
     dgapp.apply_filter('(abc)')
     call = dgapp.results.apply_filter.calls[5]
     eq_('(abc)', call['filter_str'])
Example #23
0
 def test_apply_filter_escapes_regexp(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter('()[]\\.|+?^abc')
     call = dgapp.results.apply_filter.calls[1]
     eq_('\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc', call['filter_str'])
     dgapp.apply_filter('(*)') # In "simple mode", we want the * to behave as a wilcard
     call = dgapp.results.apply_filter.calls[3]
     eq_('\(.*\)', call['filter_str'])
     dgapp.options['escape_filter_regexp'] = False
     dgapp.apply_filter('(abc)')
     call = dgapp.results.apply_filter.calls[5]
     eq_('(abc)', call['filter_str'])
Example #24
0
 def test_apply_filter_escapes_regexp(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, "apply_filter", log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter("()[]\\.|+?^abc")
     call = dgapp.results.apply_filter.calls[1]
     eq_("\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc", call["filter_str"])
     dgapp.apply_filter("(*)")  # In "simple mode", we want the * to behave as a wilcard
     call = dgapp.results.apply_filter.calls[3]
     eq_("\(.*\)", call["filter_str"])
     dgapp.options["escape_filter_regexp"] = False
     dgapp.apply_filter("(abc)")
     call = dgapp.results.apply_filter.calls[5]
     eq_("(abc)", call["filter_str"])
Example #25
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, "warning", log_calls(lambda msg: None))
     assert not app.rename_selected("foo bar 1")
     msg = logging.warning.calls[0]["msg"]
     assert msg.startswith(
         "dupeGuru Warning: 'foo bar 1' already exists in")
     names = [p.name for p in self.p.listdir()]
     assert "foo bar 1" in names
     assert "foo bar 2" in names
     eq_(g.dupes[0].name, "foo bar 2")
Example #26
0
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath["source"]
     sourcepath.mkdir()
     sourcepath["myfile"].open("w")
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, "clean_empty_dirs", log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath["dest"], 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]["path"])
Example #27
0
def test_ensures_rates(tmpdir, fake_server, monkeypatch):
    # Upon calling save and load, rates are asked for both EUR and PLN.
    app = app_entry_with_foreign_currency()
    rates_db = Currency.get_rates_db()
    monkeypatch.setattr(rates_db, 'ensure_rates',
                        log_calls(rates_db.ensure_rates))
    filename = str(tmpdir.join('foo.xml'))
    app.doc.save_to_xml(filename)
    app.doc.load_from_xml(filename)
    calls = rates_db.ensure_rates.calls
    eq_(len(calls), 1)
    eq_(set(calls[0]['currencies']), set(['PLN', 'EUR', 'CAD']))
    eq_(calls[0]['start_date'], date(2007, 10, 1))
Example #28
0
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath['source']
     sourcepath.mkdir()
     sourcepath['myfile'].open('w')
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, 'clean_empty_dirs', log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath['dest'], 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]['path'])
Example #29
0
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath["source"]
     sourcepath.mkdir()
     sourcepath["myfile"].open("w")
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, "clean_empty_dirs",
                         log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath["dest"], 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]["path"])
Example #30
0
 def test_apply_filter_escapes_regexp(self, monkeypatch):
     dgapp = TestApp().app
     monkeypatch.setattr(dgapp.results, "apply_filter",
                         log_calls(dgapp.results.apply_filter))
     dgapp.apply_filter("()[]\\.|+?^abc")
     call = dgapp.results.apply_filter.calls[1]
     eq_("\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc", call["filter_str"])
     dgapp.apply_filter(
         "(*)")  # In "simple mode", we want the * to behave as a wilcard
     call = dgapp.results.apply_filter.calls[3]
     eq_(r"\(.*\)", call["filter_str"])
     dgapp.options["escape_filter_regexp"] = False
     dgapp.apply_filter("(abc)")
     call = dgapp.results.apply_filter.calls[5]
     eq_("(abc)", call["filter_str"])
Example #31
0
 def test_copy_or_move(self, tmpdir, monkeypatch):
     # The goal here is just to have a test for a previous blowup I had. I know my test coverage
     # for this unit is pathetic. What's done is done. My approach now is to add tests for
     # every change I want to make. The blowup was caused by a missing import.
     p = Path(str(tmpdir))
     io.open(p + 'foo', 'w').close()
     monkeypatch.setattr(hscommon.conflict, 'smart_copy', log_calls(lambda source_path, dest_path: None))
     # XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
     monkeypatch.setattr(app, 'smart_copy', hscommon.conflict.smart_copy)
     monkeypatch.setattr(os, 'makedirs', lambda path: None) # We don't want the test to create that fake directory
     dgapp = TestApp().app
     dgapp.directories.add_path(p)
     [f] = dgapp.directories.get_files()
     dgapp.copy_or_move(f, True, 'some_destination', 0)
     eq_(1, len(hscommon.conflict.smart_copy.calls))
     call = hscommon.conflict.smart_copy.calls[0]
     eq_(call['dest_path'], op.join('some_destination', 'foo'))
     eq_(call['source_path'], f.path)
Example #32
0
 def test_copy_or_move(self, tmpdir, monkeypatch):
     # The goal here is just to have a test for a previous blowup I had. I know my test coverage
     # for this unit is pathetic. What's done is done. My approach now is to add tests for
     # every change I want to make. The blowup was caused by a missing import.
     p = Path(str(tmpdir))
     p['foo'].open('w').close()
     monkeypatch.setattr(hscommon.conflict, 'smart_copy', log_calls(lambda source_path, dest_path: None))
     # XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
     monkeypatch.setattr(app, 'smart_copy', hscommon.conflict.smart_copy)
     monkeypatch.setattr(os, 'makedirs', lambda path: None) # We don't want the test to create that fake directory
     dgapp = TestApp().app
     dgapp.directories.add_path(p)
     [f] = dgapp.directories.get_files()
     dgapp.copy_or_move(f, True, 'some_destination', 0)
     eq_(1, len(hscommon.conflict.smart_copy.calls))
     call = hscommon.conflict.smart_copy.calls[0]
     eq_(call['dest_path'], op.join('some_destination', 'foo'))
     eq_(call['source_path'], f.path)
Example #33
0
 def pytest_funcarg__do_setup(self, request):
     monkeypatch = request.getfuncargvalue('monkeypatch')
     monkeypatch.setattr(hscommon.util, 'delete_if_empty', log_calls(lambda path, files_to_delete=[]: None))
     # XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
     monkeypatch.setattr(app, 'delete_if_empty', hscommon.util.delete_if_empty)
     self.app = TestApp().app