def test_append_reload_and_write(self):
        history = History()

        history.append_reload_and_write("#3", self.filename, self.encoding)
        self.assertEqual(history.entries, ["#1", "#2", "#3"])

        history.append_reload_and_write("#4", self.filename, self.encoding)
        self.assertEqual(history.entries, ["#1", "#2", "#3", "#4"])
Exemple #2
0
    def test_append_reload_and_write(self):
        history = History()

        history.append_reload_and_write('#3', self.filename, self.encoding)
        self.assertEqual(history.entries, ['#1', '#2', '#3'])

        history.append_reload_and_write('#4', self.filename, self.encoding)
        self.assertEqual(history.entries, ['#1', '#2', '#3', '#4'])
Exemple #3
0
    def __init__(self, interp, config):
        """Initialise the repl.

        interp is a Python code.InteractiveInterpreter instance

        config is a populated bpython.config.Struct.
        """

        self.config = config
        self.cut_buffer = ''
        self.buffer = []
        self.interp = interp
        self.interp.syntaxerror_callback = self.clear_current_line
        self.match = False
        self.rl_history = History(duplicates=config.hist_duplicates,
                                  hist_size=config.hist_length)
        self.s_hist = []
        self.history = []
        self.evaluating = False
        self.matches_iter = MatchesIterator()
        self.funcprops = None
        self.arg_pos = None
        self.current_func = None
        self.highlighted_paren = None
        self._C = {}
        self.prev_block_finished = 0
        self.interact = Interaction(self.config)
        # previous pastebin content to prevent duplicate pastes, filled on call
        # to repl.pastebin
        self.prev_pastebin_content = ''
        self.prev_pastebin_url = ''
        self.prev_removal_url = ''
        # Necessary to fix mercurial.ui.ui expecting sys.stderr to have this
        # attribute
        self.closed = False
        self.clipboard = get_clipboard()

        pythonhist = os.path.expanduser(self.config.hist_file)
        if os.path.exists(pythonhist):
            try:
                self.rl_history.load(pythonhist,
                                     getpreferredencoding() or "ascii")
            except EnvironmentError:
                pass

        self.completers = autocomplete.get_default_completer(
            config.autocomplete_mode)
        if self.config.pastebin_helper:
            self.paster = PasteHelper(self.config.pastebin_helper)
        else:
            self.paster = PastePinnwand(self.config.pastebin_url,
                                        self.config.pastebin_expiry,
                                        self.config.pastebin_show_url,
                                        self.config.pastebin_removal_url)
    def test_save(self):
        history = History()
        history.entries = []
        for line in ["#1", "#2", "#3", "#4"]:
            history.append_to(history.entries, line)

        # save only last 2 lines
        history.save(self.filename, self.encoding, lines=2)

        # empty the list of entries and load again from the file
        history.entries = [""]
        history.load(self.filename, self.encoding)

        self.assertEqual(history.entries, ["#3", "#4"])
Exemple #5
0
    def test_save(self):
        history = History()
        history.entries = []
        for line in ['#1', '#2', '#3', '#4']:
            history.append_to(history.entries, line)

        # save only last 2 lines
        history.save(self.filename, self.encoding, lines=2)

        # empty the list of entries and load again from the file
        history.entries = ['']
        history.load(self.filename, self.encoding)

        self.assertEqual(history.entries, ['#3', '#4'])
Exemple #6
0
 def setUp(self):
     self.history = History('#%d' % x for x in range(1000))
 def setUp(self):
     self.history = History("#%d" % x for x in range(1000))
    def test_load(self):
        history = History()

        history.load(self.filename, self.encoding)
        self.assertEqual(history.entries, ["#1", "#2"])
Exemple #9
0
    def test_load(self):
        history = History()

        history.load(self.filename, self.encoding)
        self.assertEqual(history.entries, ['#1', '#2'])