예제 #1
0
 def test_compose_subp(self, tmp_f):
     with open(tmp_f, 'w') as f:
         for i in range(111111):
             f.write(str(i) + "\n")
     pipe = P | subp(f"cat {tmp_f}") | subp("grep 1") | list
     assert pipe._chain[0].cmd == f"cat {tmp_f} | grep 1"
     assert pipe()[:2] == ["1\n", "10\n"]
예제 #2
0
 def test_subp_compose(self):
     p1 = subp("grep 1")
     p2 = subp("grep 2")
     p = p1 | p2
     assert p.cmd == "grep 1 | grep 2"
     g = gen_lines(1, 101)
     assert list(p(g)) == ["12\n", "21\n"]
예제 #3
0
    def test_mid_subp(self):
        def gen_lines(n):
            for i in range(n):
                yield str(i) + "\n"

        pipe = P | gen_lines | subp("grep 1") | list
        assert pipe(11) == ["1\n", "10\n"]
예제 #4
0
 def test_source_subp(self, tmp_f):
     with open(tmp_f, 'w') as f:
         for i in range(11):
             f.write(str(i) + "\n")
     filter_1 = c(filter, lambda l: "1" in l)
     pipe = P | subp(f"cat {tmp_f}") | filter_1 | list
     assert pipe() == ["1\n", "10\n"]
예제 #5
0
 def test_input_bytes(self):
     p = subp("grep 1")
     c = b"1\n2\n11\n"
     assert list(p(c)) == [b"1\n", b"11\n"]
예제 #6
0
 def test_input_str(self):
     p = subp("grep 1")
     c = "1\n2\n11\n"
     assert list(p(c)) == ["1\n", "11\n"]
예제 #7
0
 def test_without_input(self):
     tmp_f = "/tmp/bramin_test.txt"
     with open(tmp_f, 'w') as f:
         f.write('123')
     p = subp(f"cat {tmp_f}")
     assert list(p()) == ['123']
예제 #8
0
 def test_gen_str(self):
     g = gen_lines(11, 0, -1)
     p = subp("grep 1")
     assert list(p(g)) == ["11\n", "10\n", "1\n"]