<commit_before>import os.path as osp
import unittest

from hpcbench.net import CampaignHolder
from hpcbench.cli import benet

from . test_driver import FakeBenchmark


def custom_ssh(self, *args):
    # get rid of node
    return list(args[1:])


def custom_scp(self, *args):
    src, dest = args
    if ':' in src:
        src = src.split(':', 1)[1]
    elif ':' in dest:
        dest = dest.split(':', 1)[1]
    if src != dest:
        return ['cp', src, dest]
    else:
        return ['true']


CampaignHolder.ssh = custom_ssh
CampaignHolder.scp = custom_scp


class TestNet(unittest.TestCase):
    @staticmethod
    def get_campaign_file():
        return osp.splitext(__file__)[0] + '.yaml'

    def test_local(self):
        benet.main(TestNet.get_campaign_file())<commit_msg>Execute ben-et test in temp directory<commit_after>import os.path as osp
import unittest

from hpcbench.net import CampaignHolder
from hpcbench.cli import benet

from . test_driver import FakeBenchmark
from hpcbench.toolbox.contextlib_ext import (
    mkdtemp,
    pushd,
)


def custom_ssh(self, *args):
    # get rid of node
    return list(args[1:])


def custom_scp(self, *args):
    src, dest = args
    if ':' in src:
        src = src.split(':', 1)[1]
    elif ':' in dest:
        dest = dest.split(':', 1)[1]
    if src != dest:
        return ['cp', src, dest]
    else:
        return ['true']


CampaignHolder.ssh = custom_ssh
CampaignHolder.scp = custom_scp


class TestNet(unittest.TestCase):
    @staticmethod
    def get_campaign_file():
        return osp.splitext(__file__)[0] + '.yaml'

    def test_local(self):
        with mkdtemp() as temp_dir:
            with pushd(temp_dir):
                benet.main(TestNet.get_campaign_file())
{'fraction_non_alphanumeric': 0.11896551724137931, 'fraction_numerical': 0.006896551724137931, 'mean_word_length': 2.9389140271493215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7104445', 'n_tokens_mistral': 613, 'n_tokens_neox': 587, 'n_words': 155}