Пример #1
0
    def test_read_bookmarks_file(self):
        """Should be able to parse the bookmark format"""
        f = self.gen_filename()
        self.write_fixture(f)

        manager = bookmarks.BookmarkManager(f)
        actual = self.normalise_bookmarks(manager.bookmarks)
        self.assertEqual(actual, self.expected_bookmarks)
Пример #2
0
    def test_bad_bookmark_file_data(self):
        """If the JSON has a bad structure, refuse to support bookmarks"""
        f = self.gen_filename()
        self.write_fixture(f, {'bookmarks': 'should be an object!'})

        man = bookmarks.BookmarkManager(f)
        self.assertIsNone(man.bookmarks)
        self.assertFalse(man.add_bookmark('nope', 'nope/nope/nope'))
Пример #3
0
    def test_malformed_bookmark_file(self):
        """If the JSON is malformed, refuse to support bookmarks"""
        f = self.gen_filename()
        with open(f, 'w') as ff:
            ff.write('bad json')

        man = bookmarks.BookmarkManager(f)
        self.assertIsNone(man.bookmarks)
        self.assertFalse(man.add_bookmark('nope', 'nope/nope/nope'))
Пример #4
0
    def test_unreadable_bookmark_file(self):
        """If the bookmark file is unreadable, load no bookmarks"""
        f = self.gen_filename()
        self.write_fixture(f)
        os.chmod(f, 0o200)  # TODO: Cross-platform solution?

        man = bookmarks.BookmarkManager(f)
        self.assertIsNone(man.bookmarks)
        self.assertFalse(man.add_bookmark('nope', 'nope/nope/nope'))
Пример #5
0
    def test_clean_bookmark_data(self):
        """Should ignore unexpected fields in the bookmark file"""
        f = self.gen_filename()
        data = self.data.copy()
        data['bookmarks']['foo']['hodor'] = 'foo'
        self.write_fixture(f)

        manager = bookmarks.BookmarkManager(f)
        actual = self.normalise_bookmarks(manager.bookmarks)
        self.assertEqual(actual, self.expected_bookmarks)
Пример #6
0
    def test_save_bookmarks(self):
        f = self.gen_filename()
        man1 = bookmarks.BookmarkManager(f)
        man2 = bookmarks.BookmarkManager(f)

        # Initial load of empty data
        man2.load()

        # Bookmarks are written to disk eagerly as they're added / removed
        man1.add_bookmark('mighty_bookmark', '/valley/of/strength')
        man1.add_bookmark('feeble_bookmark', '/plain/of/wimpiness')
        man1.add_bookmark('average_bookmark', '/hill/of/normality')
        man1.remove_bookmark('average_bookmark')
        expected = self.normalise_bookmarks(man1.bookmarks)

        # Check the second instance is indeed empty
        self.assertEqual(self.normalise_bookmarks(man2.bookmarks), {})

        # Now reload from disk and check it's the same as we just saved
        man2.load()
        self.assertEqual(self.normalise_bookmarks(man2.bookmarks), expected)
Пример #7
0
    def test_remove_bookmarks(self):
        f = self.gen_filename()
        self.write_fixture(f)
        manager = bookmarks.BookmarkManager(f)

        actual = self.normalise_bookmarks(manager.bookmarks)
        self.assertEqual(actual, self.expected_bookmarks)

        for b in self.data['bookmarks'].keys():
            self.assertTrue(manager.remove_bookmark(b))

        actual = self.normalise_bookmarks(manager.bookmarks)
        self.assertEqual(actual, {})
Пример #8
0
    def test_add_bookmarks(self):
        f = self.gen_filename()
        manager = bookmarks.BookmarkManager(f)
        manager.add_bookmark('foo', '/hodor/hodor/hodor')
        manager.add_bookmark('bar', '/hodor/hodor')
        manager.add_bookmark('baz', '/hodor')

        actual = manager.bookmarks
        self.assertEquals(actual.keys(), {'foo', 'bar', 'baz'})
        self.assertEquals({v.path
                           for v in actual.values()},
                          {'/hodor', '/hodor/hodor', '/hodor/hodor/hodor'})

        for v in actual.values():
            self.assertIsNotNone(v.created_on)
Пример #9
0
    def __init__(self,
                 working_dir=None,
                 ps1=None,
                 history_file=None,
                 bookmark_file=None):
        self.history_file = history_file
        self.ps1 = ps1 or Cli.DEFAULT_PS1
        self.current_path = paths.S3Path.from_path(working_dir or '/')

        self.client = client.S3Client()

        if bookmark_file:
            self.bookmarks = bookmarks.BookmarkManager(bookmark_file)
        else:
            self.bookmarks = None

        self.completion = completion.CliCompleter(self)
        self.completion.bind()
Пример #10
0
 def test_missing_bookmark_file(self):
     """Should create an empty bookmark manager if file is missing"""
     f = self.gen_filename()
     manager = bookmarks.BookmarkManager(f)
     self.assertEquals(manager.bookmarks, {})
Пример #11
0
 def test_remove_missing_bookmark(self):
     f = self.gen_filename()
     man = bookmarks.BookmarkManager(f)
     man.add_bookmark('awesome_bookmark', 'amazing/path')
     self.assertFalse(man.remove_bookmark('lame_bookmark'))