def test_walk_file_and_dir(self): expected_files = ['dfoo/foo', 'dbar/bar', 'dbiz/biz'] expected_dirs = ['dfoo', 'dbar', 'dbiz'] actual_files = [] create_file_tree(self.wordkir, expected_dirs, expected_files) source = walk.make_driver().call( walk.Sink(request=Observable.just( walk.Walk(top=self.wordkir, id='test', recursive=True)))) class TestObserver(Observer): def on_next(self, i): actual_files.append(i) def on_completed(self): return def on_error(self, e): raise Exception(e) source.response \ .filter(lambda i: type(i) is walk.WalkResponse) \ .flat_map(lambda i: i.content.directories) \ .flat_map(lambda i: i.files) \ .subscribe(TestObserver()) for f in expected_files: self.assertIn(os.path.join(self.wordkir, f), actual_files)
def test_walk_file(self): expected_files = ['foo', 'bar', 'biz'] actual_files = [] create_file_tree(self.wordkir, [], expected_files) source = walk.make_driver().call( walk.Sink(request=rx.just(walk.Walk(top=self.wordkir, id='test')))) class TestObserver(Observer): def on_next(self, i): actual_files.append(i) def on_completed(self): return def on_error(self, e): raise Exception(e) source.response.pipe( ops.filter(lambda i: type(i) is walk.WalkResponse), ops.flat_map(lambda i: i.content.files), ).subscribe(TestObserver()) for f in expected_files: self.assertIn(os.path.join(self.wordkir, f), actual_files)
def test_create(self): source = walk.make_driver().call(walk.Sink(request=Observable.empty())) self.assertIsNotNone(source)