def test_grep_if_exists_MultiLineRegexMatch(self):
        t1 = "ap\nple"

        self.args.regex = "p.p"
        app = GrepChunksApp(self.args)

        self.assertEqual(t1, app._grep_if_exists(t1))
    def test_grep_if_exists_RegexNotMatch(self):
        t1 = "apple"

        self.args.regex = "aa"
        app = GrepChunksApp(self.args)

        self.assertIsNone(app._grep_if_exists(t1))
class AppTest(unittest.TestCase):
    def setUp(self):
        self.args = MagicMock
        self.args.regex = "test_regex"
        self.app = GrepChunksApp(self.args)

    def test_feed_ThreeLinesNotMatch_OneChunk(self):
        text = "apple\norange\nboy"
        regex = re.compile("zzz")
        for line in text.split('\n'):
            self.assertIsNone(self.app._feed(line, regex))

        self.assertEqual(
            text.replace('\n', ''),
            self.app._close_partial_chunk(),
        )

    def test_feed_ThreeLinesOneLineMatch_TwoChunks(self):
        t1 = "apple"
        t2 = "orange"
        t3 = "boy"

        regex = re.compile("orange")

        self.assertIsNone(self.app._feed(t1, regex))
        self.assertEqual("apple", self.app._feed(t2, regex))
        self.assertIsNone(self.app._feed(t3, regex))

        self.assertEqual("orangeboy", self.app._close_partial_chunk())

    def test_grep_if_exists_RegexMatch(self):
        t1 = "apple"

        self.args.regex = "pp"
        app = GrepChunksApp(self.args)

        self.assertEqual(t1, app._grep_if_exists(t1))

    def test_grep_if_exists_RegexNotMatch(self):
        t1 = "apple"

        self.args.regex = "aa"
        app = GrepChunksApp(self.args)

        self.assertIsNone(app._grep_if_exists(t1))

    def test_grep_if_exists_MultiLineRegexMatch(self):
        t1 = "ap\nple"

        self.args.regex = "p.p"
        app = GrepChunksApp(self.args)

        self.assertEqual(t1, app._grep_if_exists(t1))
 def setUp(self):
     self.args = MagicMock
     self.args.regex = "test_regex"
     self.app = GrepChunksApp(self.args)