示例#1
0
def test_shell_path():
    with patch("subprocess.call") as m:
        shell = Shell("echo {path.stem} for {year}")
        shell.run(path=Path("/") / "this" / "isafile.txt",
                  year=2017,
                  simulate=False)
        m.assert_called_with("echo isafile for 2017", shell=True)
def test_shell_path():
    with patch('subprocess.call') as m:
        shell = Shell('echo {path.stem} for {year}')
        shell.run({
            'path': Path('/') / 'this' / 'isafile.txt',
            'year': 2017
        }, False)
        m.assert_called_with('echo isafile for 2017', shell=True)
def test_shell_path():
    with patch("subprocess.call") as m:
        shell = Shell("echo {path.stem} for {year}")
        shell.run({
            "path": Path("/") / "this" / "isafile.txt",
            "year": 2017
        }, False)
        m.assert_called_with("echo isafile for 2017", shell=True)
示例#4
0
def test_basic():
    config = """
    rules:
      - folders: '~/Desktop'
        filters:
          - Extension:
            - jpg
            - png
          - Extension: txt
        actions:
          - Move: {dest: '~/Desktop/New Folder', overwrite: true}
          - Echo: 'Moved {path}/{extension.upper}'
      - folders:
          - '~/test1'
          - /test2
        filters:
        actions:
          - Shell:
              cmd: 'say {path.stem}'
    """
    conf = Config.from_string(config)
    assert conf.rules == [
        Rule(
            folders=['~/Desktop'],
            filters=[Extension('.JPG', 'PNG'),
                     Extension('txt')],
            actions=[
                Move(dest='~/Desktop/New Folder', overwrite=True),
                Echo(msg='Moved {path}/{extension.upper}')
            ],
            subfolders=False,
            system_files=False,
        ),
        Rule(
            folders=['~/test1', '/test2'],
            filters=[],
            actions=[Shell(cmd='say {path.stem}')],
            subfolders=False,
            system_files=False,
        )
    ]
示例#5
0
def test_basic():
    config = """
    rules:
    - folders: '~/Desktop'
      filters:
      - extension:
        - jpg
        - png
      - extension: txt
      actions:
      - move: {dest: '~/Desktop/New Folder', overwrite: true}
      - echo: 'Moved {path}/{extension.upper}'
    - folders:
      - '~/test1'
      - '/test2'
      filters:
      actions:
      - shell:
          cmd: 'say {path.stem}'
    """
    conf = Config.from_string(config)
    assert conf.rules == [
        Rule(
            folders=["~/Desktop"],
            filters=[Extension(".JPG", "PNG"),
                     Extension("txt")],
            actions=[
                Move(dest="~/Desktop/New Folder", overwrite=True),
                Echo(msg="Moved {path}/{extension.upper}"),
            ],
            subfolders=False,
            system_files=False,
        ),
        Rule(
            folders=["~/test1", "/test2"],
            filters=[],
            actions=[Shell(cmd="say {path.stem}")],
            subfolders=False,
            system_files=False,
        ),
    ]
示例#6
0
def test_case_insensitive():
    config = """
    rules:
      - folders: '~/Desktop'
        filters:
          - extension: ['JPg', 'png']
          - Extension: txt
        actions:
          - moVe: {dest: '~/Desktop/New Folder', overwrite: true}
          - EC_HO: 'Moved {path}/{extension.upper}'
      - folders:
          - '~/test1'
          - /test2
        filters:
        actions:
          - SHELL:
              cmd: 'say {path.stem}'
    """
    conf = Config.from_string(config)
    assert conf.rules == [
        Rule(
            folders=["~/Desktop"],
            filters=[Extension(".JPG", "PNG"),
                     Extension("txt")],
            actions=[
                Move(dest="~/Desktop/New Folder", overwrite=True),
                Echo(msg="Moved {path}/{extension.upper}"),
            ],
            subfolders=False,
            system_files=False,
        ),
        Rule(
            folders=["~/test1", "/test2"],
            filters=[],
            actions=[Shell(cmd="say {path.stem}")],
            subfolders=False,
            system_files=False,
        ),
    ]
示例#7
0
def test_shell_basic():
    with patch('subprocess.call') as m:
        shell = Shell("echo 'Hello World'")
        shell.run(Path('~'), Path('~'), {}, False)
        m.assert_called_with("echo 'Hello World'", shell=True)
示例#8
0
def test_shell_attrs():
    with patch('subprocess.call') as m:
        shell = Shell('echo {year}')
        shell.run(Path('~'), Path('~'), {'year': 2017}, False)
        m.assert_called_with('echo 2017', shell=True)
示例#9
0
def test_shell_basic():
    with patch("subprocess.call") as m:
        shell = Shell("echo 'Hello World'")
        shell.run(path=Path.home(), simulate=False)
        m.assert_called_with("echo 'Hello World'", shell=True)
示例#10
0
def test_shell_args():
    with patch("subprocess.call") as m:
        shell = Shell("echo {year}")
        shell.run(path=Path.home(), year=2017, simulate=False)
        m.assert_called_with("echo 2017", shell=True)
示例#11
0
def test_shell_attrs():
    with patch("subprocess.call") as m:
        shell = Shell("echo {year}")
        shell.run({"path": Path.home(), "year": 2017}, False)
        m.assert_called_with("echo 2017", shell=True)