def test_combinations(self):
        entries = ShellmarkEntries(path=tmp_file())
        entries.add_entry(mark='dir1', path=DIR1)
        entries.add_entry(mark='dir2', path=DIR2)
        entries.add_entry(mark='dir3', path=DIR3)
        self.assertEqual(entries.get_entries(mark='dir3')[0].path, DIR3)

        # Delete one entry
        entries.delete_entries(mark='dir2')
        self.assertEqual(entries.get_entries(mark='dir3')[0].path, DIR3)

        # Sort
        entries.sort(reverse=True)
        self.assertEqual(entries.get_entries(mark='dir3')[0].path, DIR3)

        # Update one entry
        entries.update_entries(old_mark='dir1', new_path=DIR2)
        self.assertEqual(entries.get_entries(mark='dir3')[0].path, DIR3)

        entries.write()

        content = entries.get_raw()
        self.assertEqual(
            content,
            'export DIR_dir3="{0}/dir3"\nexport DIR_dir1="{0}/dir2"\n'.format(
                TEST_PATH))
 def test_method_write(self):
     old_path = os.path.join('test', 'files', 'sdirs')
     entries = ShellmarkEntries(path=old_path)
     new_path = tmp_file()
     entries.write(new_path=new_path)
     new_path_content = open(new_path, 'r').read()
     self.assertTrue(new_path_content)
コード例 #3
0
    def test_nothing_to_do(self):
        entries = ShellmarkEntries(path=tmp_file())
        entries.add_entry(mark='dir1', path=DIR1)
        entries.add_entry(mark='dir2', path=DIR2)
        entries.add_entry(mark='dir3', path=DIR3)
        entries.write()

        mock_objects = mock_main({'cleanup': True, 'sdirs': entries.path})

        entries = ShellmarkEntries(path=mock_objects['module'].params['sdirs'])
        self.assertEqual(len(mock_objects['entries'].entries), 3)
        self.assertEqual(mock_objects['entries'].entries[0].path, DIR1)

        mock_objects['module'].exit_json.assert_called_with(changed=False)