예제 #1
0
    def test_parse(self):
        test_data = '2\n*,*\n*,bar\n1\nfoo/bar\n'
        stream = io.StringIO(test_data)

        patterns, _input = Input.parse(stream)

        assert patterns == '*,*\n*,bar\n'
        assert _input.num_paths == 1
        assert _input.num_patterns == 2
        assert next(_input.stream) == 'foo/bar\n'
    def test_match(self):
        with open(path.join(TEST_DATA_DIR, 'input1.txt')) as f:
            patterns, _input = Input.parse(f)
            output = Output(io.StringIO())

            pm = PathMatcher(patterns, _input, output)
            pm.match()

        matches = output.stream.getvalue()
        matches = [match for match in matches.split('\n') if match]
        no_matches = [match for match in matches if match == 'NO MATCH']

        assert len(matches) == 5
        assert len(no_matches) == 2
예제 #3
0
 def test_has_num_paths(self, value, expected):
     _input = Input(io.StringIO())
     _input.num_paths = value
     assert _input.has_num_paths() is expected
예제 #4
0
 def test_is_heading(self, line, expected):
     _input = Input(io.StringIO())
     assert _input.is_heading(line) is expected