コード例 #1
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_generate_ising_5_iteration(run_mock):
    definition = """
sets:
 set1: 
   iterations: 5

batches: 
  batch1:
    command: generate ising
    command_options: 
      row_count: 3
      col_count: 3
    global_options:
      output: ising_{iteration}.yaml  
    """
    batches_def = yaml.load(definition, Loader=yaml.FullLoader)
    batch_module.run_batches(batches_def, simulate=False)

    assert run_mock.call_count == 5
    print(run_mock.calls)
    run_mock.assert_has_calls(
        [
            call(
                "pydcop --output ising_0.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
            call(
                "pydcop --output ising_1.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
            call(
                "pydcop --output ising_2.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
            call(
                "pydcop --output ising_3.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
            call(
                "pydcop --output ising_4.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
        ],
        any_order=True,
    )
コード例 #2
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_run_batches_iteration_only(mock_run_batch):

    definition = """
sets:
  set1:
     iterations: 5
batches:
  batch1:
    command: test
    """
    conf = yaml.load(definition, Loader=yaml.FullLoader)
    run_batches(conf, simulate=False)

    assert mock_run_batch.call_count == 5
コード例 #3
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_run_batches_direct_and_iteration(mock_run_batch):
    with tempfile.TemporaryDirectory() as tmpdirname:

        definition = f"""
sets:
  set1:
     path: {tmpdirname}
     iterations: 3
batches:
  batch1:
    command: test
    """
        conf = yaml.load(definition, Loader=yaml.FullLoader)
        run_batches(conf, simulate=False)

        assert mock_run_batch.call_count == 3
コード例 #4
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_solve_variable_row_with_dir(run_mock, tmpdir):
    dir_path = str(tmpdir.realpath())
    definition = ("""
sets:
 set1:
   path: """ + dir_path + """/*.yaml 
   iterations: 1

batches: 
  batch1:
    command: solve
    current_dir: ~/tmp/ising/{algo}/
    command_options: 
      algo: dsa
    """)

    tmpdir.join("pb1.yaml").write("")
    tmpdir.join("pb2.yaml").write("")

    batches_def = yaml.load(definition, Loader=yaml.FullLoader)
    batch_module.run_batches(batches_def, simulate=False)

    run_mock.assert_has_calls(
        [
            call(
                "pydcop solve --algo dsa " + dir_path + "/pb1.yaml",
                "~/tmp/ising/dsa/",
                None,
            ),
            call(
                "pydcop solve --algo dsa " + dir_path + "/pb2.yaml",
                "~/tmp/ising/dsa/",
                None,
            ),
        ],
        any_order=True,
    )
コード例 #5
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_generate_ising_variable_row_with_dir(run_mock):
    definition = """
sets:
 set1: 
   iterations: 1

batches: 
  batch1:
    command: generate ising
    current_dir: ~/tmp/ising/row{row_count}_col{col_count}/
    command_options: 
      row_count: [3, 4]
      col_count: 3
    global_options:
      output: ising.yaml  
    """

    batches_def = yaml.load(definition, Loader=yaml.FullLoader)
    batch_module.run_batches(batches_def, simulate=False)

    assert run_mock.call_count == 2
    run_mock.assert_has_calls(
        [
            call(
                "pydcop --output ising.yaml generate ising --col_count 3 --row_count 3",
                "~/tmp/ising/row3_col3/",
                None,
            ),
            call(
                "pydcop --output ising.yaml generate ising --col_count 3 --row_count 4",
                "~/tmp/ising/row4_col3/",
                None,
            ),
        ],
        any_order=True,
    )
コード例 #6
0
ファイル: test_batch.py プロジェクト: sankarshandamle/pyDcop
def test_generate_ising_variable_row(run_mock):
    definition = """
sets:
 set1: 
   iterations: 1

batches: 
  batch1:
    command: generate ising
    command_options: 
      row_count: [3, 4]
      col_count: 3
    global_options:
      output: ising_{iteration}_{row_count}_{col_count}.yaml  
    """

    batches_def = yaml.load(definition, Loader=yaml.FullLoader)
    batch_module.run_batches(batches_def, simulate=False)

    assert run_mock.call_count == 2

    run_mock.assert_has_calls(
        [
            call(
                "pydcop --output ising_0_3_3.yaml generate ising --col_count 3 --row_count 3",
                "",
                None,
            ),
            call(
                "pydcop --output ising_0_4_3.yaml generate ising --col_count 3 --row_count 4",
                "",
                None,
            ),
        ],
        any_order=True,
    )