<commit_before># stdlib
import os
import unittest

# 3p
import mock

# project
from checks.check_status import AgentStatus

class TestRunFiles(unittest.TestCase):
    """ Tests that runfiles (.pid, .sock, .pickle etc.) are written to internal agent folders"""

    # Mac run directory expected location
    _my_dir = os.path.dirname(os.path.abspath(__file__))
    _mac_run_dir = '/'.join(_my_dir.split('/')[:-4])
    _linux_run_dir = '/opt/datadog-agent/run'

    @mock.patch('checks.check_status._windows_commondata_path', return_value="C:\Windows\App Data")
    @mock.patch('utils.platform.Platform.is_win32', return_value=True)
    def test_agent_status_pickle_file_win32(self, *mocks):
        ''' Test pickle file location on win32 '''
        expected_path = os.path.join('C:\Windows\App Data', 'Datadog', 'AgentStatus.pickle')
        # check AgentStatus pickle created
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('utils.pidfile.PidFile.get_dir', return_value=_mac_run_dir)
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=True)
    def test_agent_status_pickle_file_mac_dmg(self, *mocks):
        ''' Test pickle file location when running a Mac DMG install '''
        expected_path = os.path.join(self._mac_run_dir, 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('utils.pidfile.tempfile.gettempdir', return_value='/a/test/tmp/dir')
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=True)
    def test_agent_status_pickle_file_mac_source(self, *mocks):
        ''' Test pickle file location when running a Mac source install '''
        expected_path = os.path.join('/a/test/tmp/dir', 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('os.path.isdir', return_value=True)
    @mock.patch('utils.pidfile.PidFile.get_dir', return_value=_linux_run_dir)
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=False)
    def test_agent_status_pickle_file_linux(self, *mocks):
        ''' Test pickle file location when running on Linux '''
        expected_path = os.path.join('/opt/datadog-agent/run', 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)<commit_msg>[Tests] Fix logic<commit_after># stdlib
import os
import unittest

# 3p
import mock

# project
from checks.check_status import AgentStatus

class TestRunFiles(unittest.TestCase):
    """ Tests that runfiles (.pid, .sock, .pickle etc.) are written to internal agent folders"""

    # Mac run directory expected location
    _my_dir = os.path.dirname(os.path.abspath(__file__))
    _mac_run_dir = '/'.join(_my_dir.split('/')[:-4]) or '/'
    _linux_run_dir = '/opt/datadog-agent/run'

    @mock.patch('checks.check_status._windows_commondata_path', return_value="C:\Windows\App Data")
    @mock.patch('utils.platform.Platform.is_win32', return_value=True)
    def test_agent_status_pickle_file_win32(self, *mocks):
        ''' Test pickle file location on win32 '''
        expected_path = os.path.join('C:\Windows\App Data', 'Datadog', 'AgentStatus.pickle')
        # check AgentStatus pickle created
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('utils.pidfile.PidFile.get_dir', return_value=_mac_run_dir)
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=True)
    def test_agent_status_pickle_file_mac_dmg(self, *mocks):
        ''' Test pickle file location when running a Mac DMG install '''
        expected_path = os.path.join(self._mac_run_dir, 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('utils.pidfile.tempfile.gettempdir', return_value='/a/test/tmp/dir')
    @mock.patch('utils.pidfile.PidFile.get_dir', return_value='')
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=True)
    def test_agent_status_pickle_file_mac_source(self, *mocks):
        ''' Test pickle file location when running a Mac source install '''
        expected_path = os.path.join('/a/test/tmp/dir', 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)

    @mock.patch('os.path.isdir', return_value=True)
    @mock.patch('utils.pidfile.PidFile.get_dir', return_value=_linux_run_dir)
    @mock.patch('utils.platform.Platform.is_win32', return_value=False)
    @mock.patch('utils.platform.Platform.is_mac', return_value=False)
    def test_agent_status_pickle_file_linux(self, *mocks):
        ''' Test pickle file location when running on Linux '''
        expected_path = os.path.join('/opt/datadog-agent/run', 'AgentStatus.pickle')
        self.assertEqual(AgentStatus._get_pickle_path(), expected_path)
{'fraction_non_alphanumeric': 0.1318809570122544, 'fraction_numerical': 0.005446411204045905, 'mean_word_length': 4.564935064935065, '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': '6692059', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1664, 'n_words': 278}