Python six.assertRegex() Examples

The following are 28 code examples of six.assertRegex(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module six , or try the search function .
Example #1
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_pass_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_pass with no argument.
        Then: log_pass logs with a zero-length description.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_pass("")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("pass,,,\r\n")) 
Example #2
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_fail_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_fail with no argument.
        Then: log_fail logs with a zero-length description.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_fail("")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("fail,,,\r\n")) 
Example #3
Source File: test_dropbox.py    From dropbox-sdk-python with MIT License 6 votes vote down vote up
def test_default_oauth2_urls(self):
        flow_obj = DropboxOAuth2Flow('dummy_app_key', 'dummy_app_secret',
            'http://localhost/dummy', 'dummy_session', 'dbx-auth-csrf-token')

        six.assertRegex(
            self,
            flow_obj._get_authorize_url('http://localhost/redirect', 'state', 'legacy'),
            r'^https://{}/oauth2/authorize\?'.format(re.escape(session.WEB_HOST)),
        )

        self.assertEqual(
            flow_obj.build_url('/oauth2/authorize'),
            'https://{}/oauth2/authorize'.format(session.API_HOST),
        )

        self.assertEqual(
            flow_obj.build_url('/oauth2/authorize', host=session.WEB_HOST),
            'https://{}/oauth2/authorize'.format(session.WEB_HOST),
        ) 
Example #4
Source File: turbinia.py    From dftimewolf with Apache License 2.0 6 votes vote down vote up
def testSetup(self, _mock_TurbiniaClient):
    """Tests that the processor is set up correctly."""
    test_state = state.DFTimewolfState(config.Config)
    turbinia_processor = turbinia.TurbiniaProcessor(test_state)
    turbinia_processor.SetUp(
        disk_name='disk-1',
        project='turbinia-project',
        turbinia_zone='europe-west1',
        sketch_id=123,
        run_all_jobs=False)
    self.assertEqual(turbinia_processor.disk_name, 'disk-1')
    self.assertEqual(turbinia_processor.project, 'turbinia-project')
    self.assertEqual(turbinia_processor.turbinia_zone, 'europe-west1')
    self.assertEqual(turbinia_processor.sketch_id, 123)
    self.assertEqual(turbinia_processor.run_all_jobs, False)
    self.assertEqual(test_state.errors, [])

    # TURBINIA_REGION is dynamically generated
    # pylint: disable=no-member
    self.assertEqual(turbinia_processor.turbinia_region,
                     turbinia.turbinia_config.TURBINIA_REGION)
    # pylint: disable=protected-access
    six.assertRegex(self, turbinia_processor._output_path,
                    '(/tmp/tmp|/var/folders).+') 
Example #5
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_error_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_error with an empty string.
        Then: log_error logs with a zero-length description.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_error("")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("error,,,\r\n")) 
Example #6
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_check_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_check with an empty string.
        Then: log_check logs with a zero-length description.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_check("")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("check,,,\r\n")) 
Example #7
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_open_test_step_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling open_test_step with an empty string.
        Then: open_test_step logs with a zero-length description.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.open_test_step("")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("open step,,,\r\n")) 
Example #8
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_pass(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_pass with some description.
        Then: open_test_case logs as expected.
         and: log_pass logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_pass(self.some_log_pass_msg)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("pass,,," + self.some_log_pass_msg + "\r\n")
        ) 
Example #9
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_fail(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_fail with some description.
        Then: open_test_case logs as expected.
         and: log_fail logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_fail(self.some_log_fail_msg)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("fail,,," + self.some_log_fail_msg + "\r\n")
        ) 
Example #10
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_open_test_case(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
        Then: open_test_case logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        ) 
Example #11
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def test_log_info(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_info with some description.
        Then: open_test_case logs as expected.
         and: log_info logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_info(self.some_log_info_msg)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self, self.virtual_file.readline(), LOGGER_PREAMBLE + re.escape("info,,," + self.some_log_info_msg + "\r\n")
        ) 
Example #12
Source File: test_timer.py    From chainer with MIT License 5 votes vote down vote up
def test_print_report(self):
        x = self.x
        self.f.apply((chainer.Variable(x),))
        self.f.apply((chainer.Variable(x),))
        io = six.StringIO()
        self.h.print_report(unit=self.unit, file=io)
        expect = r'''\AFunctionName +ElapsedTime +Occurrence
 +Exp +[0-9.\-e]+(.s|sec) +[0-9]+
\Z'''
        actual = io.getvalue()
        six.assertRegex(self, actual, expect) 
Example #13
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_log_send_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_send with an empty buffer.
        Then: log_send logs with zero-length data.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_send(b"")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE
            + re.escape("send,0," + fuzz_logger_csv.DEFAULT_HEX_TO_STR(bytes(b"")) + "," + repr(b"") + "\r\n"),
        ) 
Example #14
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_log_recv_empty(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_recv with an empty buffer.
        Then: log_recv logs with zero-length data.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_recv(b"")

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE
            + re.escape("recv,0," + fuzz_logger_csv.DEFAULT_HEX_TO_STR(bytes(b"")) + "," + repr(b"") + "\r\n"),
        ) 
Example #15
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_log_send(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_send with some data.
        Then: open_test_case logs as expected.
         and: log_send logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_send(self.some_send_data)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE
            + re.escape(
                "send,"
                + str(len(self.some_send_data))
                + ","
                + fuzz_logger_csv.DEFAULT_HEX_TO_STR(self.some_send_data)
                + ","
                + repr(self.some_send_data)
                + "\r\n"
            ),
        ) 
Example #16
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_log_recv(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_recv with some data.
        Then: open_test_case logs as expected.
         and: log_recv logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_recv(self.some_recv_data)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE
            + re.escape(
                "recv,"
                + str(len(self.some_recv_data))
                + ","
                + fuzz_logger_csv.DEFAULT_HEX_TO_STR(self.some_recv_data)
                + ","
                + repr(self.some_recv_data)
                + "\r\n"
            ),
        ) 
Example #17
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_log_check(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_check with some description.
        Then: open_test_case logs as expected.
         and: log_check logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_check(self.some_log_check_msg)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("check,,," + self.some_log_check_msg + "\r\n"),
        ) 
Example #18
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_open_test_step(self):
        """
        Given: FuzzLoggerCsv with a virtual file handle.
        When: Calling open_test_case with some test_case_id.
         and: Calling open_test_step with some description.
        Then: open_test_case logs as expected.
         and: open_test_step logs as expected.
        """
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.open_test_step(self.some_test_step_msg)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open step,,," + self.some_test_step_msg + "\r\n"),
        ) 
Example #19
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_get_time_stamp(self):
        """
        Given: No context.
        When: Calling get_time_stamp().
        Then: get_time_stamp() returns time stamp in proper format.
        """
        # When
        s = fuzz_logger_csv.get_time_stamp()

        # Then
        six.assertRegex(self, s, r"\d\d\d\d-\d\d-\d\d\w\d\d:\d\d:\d\d.\d*") 
Example #20
Source File: test_fuzz_logger_text.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def test_get_time_stamp(self):
        """
        Given: No context.
        When: Calling get_time_stamp().
        Then: get_time_stamp() returns time stamp in proper format.
        """
        # When
        s = boofuzz.helpers.get_time_stamp()

        # Then
        six.assertRegex(self, s, r"\[\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d,\d\d\d\]") 
Example #21
Source File: test_six.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test() 
Example #22
Source File: test_six.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test() 
Example #23
Source File: test_six.py    From c4ddev with MIT License 5 votes vote down vote up
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test() 
Example #24
Source File: test_six.py    From six with MIT License 5 votes vote down vote up
def test_assertRegex():
    class TestAssertRegex(unittest.TestCase):
        def test(self):
            with self.assertRaises(AssertionError):
                six.assertRegex(self, 'test', r'^a')

            six.assertRegex(self, 'test', r'^t')

    TestAssertRegex('test').test() 
Example #25
Source File: config_parser_test.py    From gin-config with Apache License 2.0 5 votes vote down vote up
def testInvalidBasicType(self):
    with self.assertRaises(SyntaxError) as assert_raises:
      self._parse_config("""
        scope/some_fn.arg1 = None
        scope/some_fn.arg2 = Garbage  # <-- Not a valid Python value.
      """)
    self.assertEqual(assert_raises.exception.lineno, 3)
    self.assertEqual(assert_raises.exception.offset, 29)
    self.assertEqual(
        assert_raises.exception.text.strip(),
        'scope/some_fn.arg2 = Garbage  # <-- Not a valid Python value.')
    six.assertRegex(self, str(assert_raises.exception),
                    r"malformed (string|node or string: <_ast.Name [^\n]+>)\n"
                    r"    Failed to parse token 'Garbage' \(line 3\)") 
Example #26
Source File: test_cupy_memory_profile.py    From chainer with MIT License 5 votes vote down vote up
def test_print_report(self):
        io = six.StringIO()
        self.h.print_report(unit=self.unit, file=io)
        expect = r'''\AFunctionName  UsedBytes  AcquiredBytes  Occurrence
 +Exp +[0-9.\-e]+.?B +[0-9.\-e]+.?B +[0-9]+
 +ReLU +[0-9.\-e]+.?B +[0-9.\-e]+.?B +[0-9]+$
'''
        actual = io.getvalue()
        six.assertRegex(self, actual, expect) 
Example #27
Source File: test_pagure_flask_ui_quick_reply.py    From pagure with GNU General Public License v2.0 5 votes vote down vote up
def assertQuickReplyLinks(self, output):
        """Assert reply links created by setup_quick_replies are present."""
        link = r'data-qr="%s">\s*%s\s*</a>'
        six.assertRegex(
            self, output.get_data(as_text=True), link % (self.r1, self.sr1)
        )
        six.assertRegex(
            self, output.get_data(as_text=True), link % (self.r2, self.sr2)
        ) 
Example #28
Source File: test_fuzz_logger_csv.py    From boofuzz with GNU General Public License v2.0 4 votes vote down vote up
def test_hex_to_str_function(self):
        """
        Verify that the UUT uses the custom hex_to_str function, if provided.

        Given: FuzzLoggerCsv with a virtual file handle and custom hex_to_str
               function.
        When: Calling open_test_case with some test_case_id.
         and: Calling log_recv with some data.
        Then: open_test_case logs as expected.
         and: log_recv logs as expected, using the custom hex_to_str function.
        """

        # Given
        def hex_to_str(hex_data):
            return repr(hex_data)

        self.logger = fuzz_logger_csv.FuzzLoggerCsv(file_handle=self.virtual_file, bytes_to_str=hex_to_str)
        # When
        self.logger.open_test_case(
            self.some_test_case_id, name=self.some_test_case_name, index=self.some_test_case_index
        )
        self.logger.log_recv(self.some_recv_data)

        # Then
        self.virtual_file.seek(0)
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE + re.escape("open test case,,,Test case " + self.some_test_case_id + "\r\n"),
        )
        six.assertRegex(
            self,
            self.virtual_file.readline(),
            LOGGER_PREAMBLE
            + re.escape(
                "recv,"
                + str(len(self.some_recv_data))
                + ","
                + hex_to_str(self.some_recv_data)
                + ","
                + repr(self.some_recv_data)
                + "\r\n"
            ),
        )