Пример #1
0
    def test_read(self):
        """Test the return value of BinYes.read()

        @todo: Decide on a policy for str vs. unicode
        """
        self.assertRegexpMatches(BinYes.read(), '(y\n)+',
            "read() must return a sequence of one or more 'y\\n' substrings")
        self.assertRegexpMatches(BinYes.read(10), '(y\n)+',
            "read(i) must return a sequence of one or more 'y\\n' substrings")
        self.assertLessEqual(len(BinYes.read(10)), 10,
            "read(10) must return no more than 10 characters.")

        for i in xrange(0, 100):
            self.assertRegexpMatches(BinYes.read(), '(y\n)+',
                "read() must support being called any number of times")

        #TODO: Move what follows into test_read_odd() once it doesn't fail.
        req_len = 5
        self.assertNotEqual(req_len % 2, 0,
            "This test is broken and requires a request length that would "
            "split a 'y\\n' substring.")

        test_return = BinYes.read(req_len)
        self.assertLessEqual(len(test_return), req_len,
            "read() may return a string shorter than request but not longer.")
Пример #2
0
    def test_read(self):
        """Test the return value of BinYes.read()

        @todo: Decide on a policy for str vs. unicode
        """
        self.assertRegexpMatches(
            BinYes.read(), '(y\n)+',
            "read() must return a sequence of one or more 'y\\n' substrings")
        self.assertRegexpMatches(
            BinYes.read(10), '(y\n)+',
            "read(i) must return a sequence of one or more 'y\\n' substrings")
        self.assertLessEqual(
            len(BinYes.read(10)), 10,
            "read(10) must return no more than 10 characters.")

        for i in xrange(0, 100):
            self.assertRegexpMatches(
                BinYes.read(), '(y\n)+',
                "read() must support being called any number of times")

        #TODO: Move what follows into test_read_odd() once it doesn't fail.
        req_len = 5
        self.assertNotEqual(
            req_len % 2, 0,
            "This test is broken and requires a request length that would "
            "split a 'y\\n' substring.")

        test_return = BinYes.read(req_len)
        self.assertLessEqual(
            len(test_return), req_len,
            "read() may return a string shorter than request but not longer.")
Пример #3
0
    def test_read_odd(self):
        """Test that odd read() sizes don't break the 'y\\n' pairs."""
        self.assertLessEqual(len(BinYes.read(1)), 1,
            "read(1) must return no more than 1 character.")
        self.assertEqual(len(BinYes.read(1)), 1,
            "read(1) may not return zero characters because it could "
            "break fragile subprocesses.")

        self.fail("BinYes needs to be redesigned to ensure that read(1) can be"
            " supported without risking a subprocess receiving '\\n' as its"
            " first line of input and assuming it to mean 'use default'"
            " because a previous user of BinYes read an odd number of"
            " characters.")
Пример #4
0
    def test_read_odd(self):
        """Test that odd read() sizes don't break the 'y\\n' pairs."""
        self.assertLessEqual(len(BinYes.read(1)), 1,
                             "read(1) must return no more than 1 character.")
        self.assertEqual(
            len(BinYes.read(1)), 1,
            "read(1) may not return zero characters because it could "
            "break fragile subprocesses.")

        self.fail(
            "BinYes needs to be redesigned to ensure that read(1) can be"
            " supported without risking a subprocess receiving '\\n' as its"
            " first line of input and assuming it to mean 'use default'"
            " because a previous user of BinYes read an odd number of"
            " characters.")
Пример #5
0
    def test_fileno(self):
        """Test the fileno() method of util.BinYes"""
        self.assertTrue(hasattr(BinYes, 'fileno'),
                "BinYes must have a fileno() method for compatibility.")

        self.assertIsNone(BinYes.fileno(),
                "fileno() must return None if there's no OS-level file"
                "handle associated with it as in BinYes.")
Пример #6
0
    def test_fileno(self):
        """Test the fileno() method of util.BinYes"""
        self.assertTrue(
            hasattr(BinYes, 'fileno'),
            "BinYes must have a fileno() method for compatibility.")

        self.assertIsNone(
            BinYes.fileno(),
            "fileno() must return None if there's no OS-level file"
            "handle associated with it as in BinYes.")