Example #1
0
    def test_plugin(self, tmp_path):
        fop = FileOps(tmp_path)

        class Plugin:
            def apply(self, source, dest):
                self.called = True
                self.source = source
                self.dest = dest

            def strify(self, op):
                return 'Plugin.apply'

        plugin = Plugin()
        fop.plugin(plugin.apply, 'source', 'dest')
        assert fop.ops == [(plugin.apply, ('source', 'dest'))]
        fop.apply()
        assert plugin.called
        assert plugin.source == str(tmp_path / 'source')
        assert plugin.dest == str(tmp_path / 'dest')
Example #2
0
    def test_str(self, tmp_path):
        class Plugin:
            def apply(self, source, dest):
                self.called = True
                self.source = source
                self.dest = dest

            def strify(self, op):
                return 'Plugin.apply'

        plugin = Plugin()
        fop = FileOps(tmp_path)

        fop.copy('foo', 'bar')
        fop.remove('file')
        fop.plugin(plugin.apply, 'source', 'dest')

        assert str(fop) == ('COPY "foo" -> "bar"\nREMOVE "file"\n'
                            'Plugin.apply "source" -> "dest"')