Esempio n. 1
0
    def it_shows_error_on_stop_for_slow_start(self):
        assert_command(
            ('pgctl-2015', 'start', 'slow-startup'),
            '',
            '''\
[pgctl] Starting: slow-startup
[pgctl] Started: slow-startup
''',
            0,
        )
        assert_command(
            ('pgctl-2015', 'restart', 'slow-startup'),
            '''\
==> playground/slow-startup/stdout.log <==

==> playground/slow-startup/stderr.log <==
pgctl-poll-ready: service's ready check succeeded
pgctl-poll-ready: service is stopping -- quitting the poll
''',
            S(
                self.LOCKERROR.format(service='slow-startup',
                                      time='5',
                                      cmd='sleep 987654')),
            1,
        )
Esempio n. 2
0
    def it_shows_error_on_stop_for_sweet(self):
        assert_command(
            ('pgctl-2015', 'start', 'sweet'),
            '',
            '''\
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
            0,
        )
        assert_command(
            ('pgctl-2015', 'restart', 'sweet'),
            '''\
==> playground/sweet/stdout.log <==
sweet

==> playground/sweet/stderr.log <==
sweet_error
''',
            S(
                self.LOCKERROR.format(service='sweet',
                                      time='5',
                                      cmd='sleep infinity')),
            1,
        )
Esempio n. 3
0
    def it_cant_parse_nonsense(self, tmpdir):
        conffile = tmpdir.join('my.nonsense')
        conffile.write(example1.yaml)

        with ShouldRaise(
                C.UnrecognizedConfig(
                    S(r'Unknown config type: .*/my\.nonsense'))):
            example1.config.from_file(conffile.strpath)
Esempio n. 4
0
 def test_order_doesnt_matter_ok(self):
     capture = LogCapture.make(self)
     log.info('Failed to send BAR')
     log.info('Sent FOO, length 1234')
     log.info('Sent 1 Messages')
     capture.check((INFO, S('Sent FOO, length \d+')),
                   (INFO, 'Failed to send BAR'), (INFO, 'Sent 1 Messages'),
                   order_matters=False)
Esempio n. 5
0
 def it_displays_correctly_when_the_service_is_up(self, in_example_dir):
     check_call(('pgctl-2015', 'start', 'sleep'))
     assert_command(
         ('pgctl-2015', 'status', 'sleep'),
         S('sleep: ready \\(pid \\d+\\) \\d+ seconds\\n$'),
         '',
         0,
     )
Esempio n. 6
0
    def it_logs_continuously_when_run_interactively(self, in_example_dir):
        check_call(('pgctl', 'start'))

        # this pty simulates running in a terminal
        read, write = os.openpty()
        pty.normalize_newlines(read)
        p = Popen(('pgctl', 'log'), stdout=write, stderr=write)
        os.close(write)

        import fcntl
        fl = fcntl.fcntl(read, fcntl.F_GETFL)
        fcntl.fcntl(read, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        assert p.poll() is None  # it's still running

        # needs to loop for several seconds because the default event loop
        # in tail-f is one second.
        # TODO: buf is a list, use wait_for() to append to it
        limit = 3.0
        wait = .1
        buf = b''
        while True:
            try:
                block = os.read(read, 1024)
                print('BLOCK:', block)
            except OSError as error:
                print('ERROR:', error)
                if error.errno == 11:  # other end didn't write yet
                    if limit > 0:
                        import time
                        time.sleep(wait)
                        limit -= wait
                        continue
                    else:
                        break
                else:
                    raise
            buf += block

        from testfixtures import StringComparison as S
        buf = norm.pgctl(buf.decode('UTF-8'))
        print('NORMED:')
        print(buf)
        assert buf == S('''(?s)\
==> playground/ohhi/log <==
{TIMESTAMP} [oe].*
==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error

==> playground/ohhi/log <==
.*{TIMESTAMP} .*$''')
        assert p.poll() is None  # it's still running

        p.terminate()

        assert p.wait() == -15
Esempio n. 7
0
 def it_explodes_on_ambiguity(self, tmpdir):
     conffile = tmpdir.join('example1.ini')
     conffile.write(example1.ini)
     conffile = tmpdir.join('example1.conf')
     conffile.write(example1.ini)
     with ShouldRaise(
             C.AmbiguousConfig(
                 S(r'multiple configurations found at .*/example1\.\*'))):
         example1.config.from_path_prefix(tmpdir.strpath + '/')
Esempio n. 8
0
 def test_sort(self):
     a = S('a')
     b = S('b')
     c = S('c')
     compare(sorted((
         'd',
         c,
         'e',
         a,
         'a1',
         b,
     )), [
         a,
         'a1',
         b,
         c,
         'd',
         'e',
     ])
Esempio n. 9
0
    def it_logs_continuously_when_run_interactively(self, in_example_dir):
        check_call(('pgctl-2015', 'start'))

        # this pty simulates running in a terminal
        read, write = os.openpty()
        pty_normalize_newlines(read)
        p = Popen(('pgctl-2015', 'log'), stdout=write, stderr=write)
        os.close(write)

        import fcntl
        fl = fcntl.fcntl(read, fcntl.F_GETFL)
        fcntl.fcntl(read, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        assert p.poll() is None  # it's still running

        # needs to loop for at least two seconds because the default event loop
        # in tail-f is one second.
        retries = 20
        buf = ''
        while True:
            try:
                block = os.read(read, 1024)
                print('BLOCK:', block)
            except OSError as error:
                print('ERROR:', error)
                if error.errno == 11:  # other end didn't write yet
                    if retries > 0:
                        retries -= 1
                        import time
                        time.sleep(.1)
                        continue
                    else:
                        break
                else:
                    raise
            buf += block

        assert buf == S('''(?s)\
==> playground/ohhi/stdout\\.log <==
o.*
==> playground/ohhi/stderr\\.log <==
e.*
==> playground/sweet/stdout\\.log <==
sweet

==> playground/sweet/stderr\\.log <==
sweet_error
.*$''')
        assert p.poll() is None  # it's still running

        p.terminate()

        assert p.wait() == -15
Esempio n. 10
0
    def it_displays_the_status_of_all_services(self, in_example_dir):
        """Expect all services to provide status when no service is specified"""
        check_call(('pgctl-2015', 'start', 'tail'))
        assert_command(
            ('pgctl-2015', 'status'),
            S('''\
sleep: down
tail: ready \\(pid \\d+\\) \\d+ seconds
$'''),
            '',
            0,
        )
Esempio n. 11
0
    def it_displays_the_status_of_multiple_services(self, in_example_dir):
        """Expect multiple services with status and PID"""
        check_call(('pgctl-2015', 'start', 'sleep'))
        assert_command(
            ('pgctl-2015', 'status', 'sleep', 'tail'),
            S('''\
sleep: ready \\(pid \\d+\\) \\d+ seconds
tail: down
$'''),
            '',
            0,
        )
Esempio n. 12
0
 def test_warning_no_csq_for_variants(self):
     logging.disable(logging.NOTSET)
     with LogCapture() as l:
         temp_path = tempfile.TemporaryDirectory()
         os.symlink(os.path.join(self.test_data_dir, 'input.no_csq.vcf'), os.path.join(temp_path.name, 'input.vcf'))
         command = [
             os.path.join(temp_path.name, 'input.vcf'),
             os.path.join(self.test_data_dir, 'genes.fpkm_tracking'),
             'cufflinks',
             'gene',
         ]
         vcf_expression_annotator.main(command)
         temp_path.cleanup()
         l.check_present(('root', 'WARNING', S("Variant is missing VEP annotation. INFO column doesn't contain CSQ field for variant")))
Esempio n. 13
0
    def test_class(self):
        class SomethingElse:
            pass

        if PY2:
            text = ("<class mortar_rdb.tests.test_controlled_schema."
                    "SomethingElse at [0-9a-zA-Z]+>")
        else:
            text = ("<class 'mortar_rdb.tests.test_controlled_schema."
                    "TestSource.test_class.<locals>.SomethingElse'>")

        with ShouldRaise(
                TypeError(
                    S(text + " must be a "
                      "Table object or a declaratively mapped model class."))):
            s = Source(SomethingElse)
Esempio n. 14
0
    def it_fails_by_default(self):
        check_call(('pgctl-2015', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl-2015', 'stop'),
            '''\
==> playground/sweet/stdout.log <==
sweet

==> playground/sweet/stderr.log <==
sweet_error
''',
            S(
                self.LOCKERROR.format(service='sweet',
                                      time='1\\.5',
                                      cmd='sleep 2\\.25')),
            1,
        )
Esempio n. 15
0
 def test_order_doesnt_matter_extra_in_expected(self):
     capture = LogCapture.make(self)
     log.info('Failed to send BAR')
     log.info('Sent FOO, length 1234')
     with ShouldAssert("entries not as expected:\n"
                       "\n"
                       "expected and found:\n"
                       "[(<LogLevel=info>, 'Failed to send BAR'),\n"
                       " (<LogLevel=info>, <S:Sent FOO, length 1234>)]\n"
                       "\n"
                       "expected but not found:\n"
                       "[(<LogLevel=info>, 'Sent 1 Messages')]\n"
                       "\n"
                       "other entries:\n"
                       "[]"):
         capture.check((INFO, S('Sent FOO, length 1234')),
                       (INFO, 'Failed to send BAR'),
                       (INFO, 'Sent 1 Messages'),
                       order_matters=False)
Esempio n. 16
0
 def test_order_doesnt_matter_failure(self):
     capture = LogCapture.make(self)
     log.info('Failed to send BAR')
     log.info('Sent FOO, length 1234')
     log.info('Sent 1 Messages')
     with ShouldAssert(
             "entries not as expected:\n"
             "\n"
             "expected and found:\n"
             "[(<LogLevel=info>, 'Failed to send BAR'), (<LogLevel=info>, 'Sent 1 Messages')]\n"
             "\n"
             "expected but not found:\n"
             "[(<LogLevel=info>, <S:Sent FOO, length abc>)]\n"
             "\n"
             "other entries:\n"
             "[(<LogLevel=info>, {}'Sent FOO, length 1234')]".format(
                 '' if PY3 else 'u')):
         capture.check((INFO, S('Sent FOO, length abc')),
                       (INFO, 'Failed to send BAR'),
                       (INFO, 'Sent 1 Messages'),
                       order_matters=False)
Esempio n. 17
0
 def test_cmp_no(self):
     self.failUnless(cmp(S('on \d+'), 'on xx'))
Esempio n. 18
0
 def test_cmp_yes(self):
     self.failIf(cmp(S('on \d+'), 'on 4040'))
Esempio n. 19
0
 def test_flags_names(self):
     compare(S(".*BaR", dotall=True, ignorecase=True), actual="foo\nbar")
Esempio n. 20
0
 def test_str(self):
     compare('<S:on \\d+>', str(S('on \d+')))
Esempio n. 21
0
 def test_repr(self):
     compare('<S:on \\d+>', repr(S('on \d+')))
Esempio n. 22
0
 def test_not_string(self):
     self.failIf(40220 == S('on \d+'))
Esempio n. 23
0
 def test_comp_in_sequence(self):
     self.failUnless((1, 2, 'on 40220') == (1, 2, S('on \d+')))
Esempio n. 24
0
 def test_not_equal_no(self):
     self.failUnless('on xxx' != S('on \d+'))
Esempio n. 25
0
 def test_not_equal_yes(self):
     self.failIf('on 40220' != S('on \d+'))
Esempio n. 26
0
 def test_equal_yes(self):
     self.failUnless('on 40220' == S('on \d+'))
Esempio n. 27
0
 def test_flags_parameter(self):
     compare(S(".*bar", flags=re.DOTALL), actual="foo\nbar")
Esempio n. 28
0
 def test_equal_no(self):
     self.failIf('on xxx' == S('on \d+'))
Esempio n. 29
0
 def test_flags_argument(self):
     compare(S(".*bar", re.DOTALL), actual="foo\nbar")