def print_jobs(self, jobstore=None, out=None): """ print_jobs(jobstore=None, out=sys.stdout) Prints out a textual listing of all jobs currently scheduled on either all job stores or just a specific one. :param str|unicode jobstore: alias of the job store, ``None`` to list jobs from all stores :param file out: a file-like object to print to (defaults to **sys.stdout** if nothing is given) """ out = out or sys.stdout with self._jobstores_lock: if self._pending_jobs: print(six.u('Pending jobs:'), file=out) for job, jobstore_alias, replace_existing in self._pending_jobs: if jobstore in (None, jobstore_alias): print(six.u(' %s') % job, file=out) for alias, store in six.iteritems(self._jobstores): if jobstore in (None, alias): print(six.u('Jobstore %s:') % alias, file=out) jobs = store.get_all_jobs() if jobs: for job in jobs: print(six.u(' %s') % job, file=out) else: print(six.u(' No scheduled jobs'), file=out)
def test_print_encoding(monkeypatch): # Fool the type checking in print_. monkeypatch.setattr(six, "file", six.BytesIO, raising=False) out = six.BytesIO() out.encoding = "utf-8" out.errors = None six.print_(six.u("\u053c"), end="", file=out) assert out.getvalue() == six.b("\xd4\xbc") out = six.BytesIO() out.encoding = "ascii" out.errors = "strict" py.test.raises(UnicodeEncodeError, six.print_, six.u("\u053c"), file=out) out.errors = "backslashreplace" six.print_(six.u("\u053c"), end="", file=out) assert out.getvalue() == six.b("\\u053c")
def __unicode__(self): if hasattr(self, 'next_run_time'): status = 'next run at: ' + datetime_repr(self.next_run_time) if self.next_run_time else 'paused' else: status = 'pending' return six.u('%s (trigger: %s, %s)') % (self.name, self.trigger, status)
def test_python_2_unicode_compatible(): @six.python_2_unicode_compatible class MyTest(object): def __str__(self): return six.u('hello') def __bytes__(self): return six.b('hello') my_test = MyTest() if six.PY2: assert str(my_test) == six.b("hello") assert unicode(my_test) == six.u("hello") elif six.PY3: assert bytes(my_test) == six.b("hello") assert str(my_test) == six.u("hello") assert getattr(six.moves.builtins, 'bytes', str)(my_test) == six.b("hello")
def test_print_(): save = sys.stdout out = sys.stdout = six.moves.StringIO() try: six.print_("Hello,", "person!") finally: sys.stdout = save assert out.getvalue() == "Hello, person!\n" out = six.StringIO() six.print_("Hello,", "person!", file=out) assert out.getvalue() == "Hello, person!\n" out = six.StringIO() six.print_("Hello,", "person!", file=out, end="") assert out.getvalue() == "Hello, person!" out = six.StringIO() six.print_("Hello,", "person!", file=out, sep="X") assert out.getvalue() == "Hello,Xperson!\n" out = six.StringIO() six.print_(six.u("Hello,"), six.u("person!"), file=out) result = out.getvalue() assert isinstance(result, six.text_type) assert result == six.u("Hello, person!\n") six.print_("Hello", file=None) # This works. out = six.StringIO() six.print_(None, file=out) assert out.getvalue() == "None\n" class FlushableStringIO(six.StringIO): def __init__(self): six.StringIO.__init__(self) self.flushed = False def flush(self): self.flushed = True out = FlushableStringIO() six.print_("Hello", file=out) assert not out.flushed six.print_("Hello", file=out, flush=True) assert out.flushed
def test_StringIO(): fp = six.StringIO() fp.write(six.u("hello")) assert fp.getvalue() == six.u("hello")
def test_unichr(): assert six.u("\u1234") == six.unichr(0x1234) assert type(six.u("\u1234")) is type(six.unichr(0x1234))
def test_u_escapes(): s = six.u("\u1234") assert len(s) == 1
def test_u(): s = six.u("hi \u0439 \U00000439 \\ \\\\ \n") assert isinstance(s, unicode) assert s == "hi \xd0\xb9 \xd0\xb9 \\ \\\\ \n".decode("utf8")
def test_text_type(): assert type(six.u("hi")) is six.text_type
def __init__(self, job_id): super(JobLookupError, self).__init__( six.u('No job by the id of %s was found') % job_id)
def __str__(self): return six.u('hello')
def test_u(): s = six.u("hi \u0439 \U00000439 \\ \\\\ \n") assert isinstance(s, str) assert s == "hi \u0439 \U00000439 \\ \\\\ \n"
def test_string_types(): assert isinstance("hi", six.string_types) assert isinstance(six.u("hi"), six.string_types) assert issubclass(six.text_type, six.string_types)
def __init__(self, job_id): super(ConflictingIdError, self).__init__( six.u('Job identifier (%s) conflicts with an existing job') % job_id)