<commit_before>import json
import unittest
from unittest import TestCase
from mock import MagicMock, patch
mock_arcpy = MagicMock()
patch.dict("sys.modules", arcpy=mock_arcpy).start()

from ags_publishing_tools.MapServicePublisher import MapServicePublisher

class TestMapServicePublisher(TestCase):
    m = None

    def setUp(self):
        self.m = MapServicePublisher()
        self.m.config = {
            'connectionFilePath': 'my/connection',
            'mapServices': {
                'services': [
                    {
                        'input': 'foo'
                    }
                ]
            }
        }

    def connection_file_paths_match(self, path, config):
        self.assertEqual(self.m.currentDirectory + path, self.m.get_connection_file_path('mapServices', config))

    def test_get_top_level_connection_file_path(self):
        self.connection_file_paths_match('my/connection', {'input': 'foo'})

    def test_get_type_level_connection_file_path(self):
        self.m.config = {
            'mapServices': {
                'connectionFilePath': 'my/type/connection',
                'services': [
                    {
                        'input': 'foo'
                    }
                ]
            }
        }
        self.connection_file_paths_match('my/type/connection', {'input': 'foo'})

    def test_get_service_level_connection_file_path(self):
        self.m.config = {
            'mapServices': {
                'services': [
                    {
                        'input': 'foo',
                        'connectionFilePath': 'my/service/connection'
                    }
                ]
            }
        }
        self.connection_file_paths_match('my/service/connection', {
            'input': 'foo',
            'connectionFilePath': 'my/service/connection'
        })

    def test_raise_exception_when_input_not_found(self):
        with self.assertRaises(ValueError):
            self.m.publish_input('bar')

    def test_check_service_type_with_backslashes_in_input(self):
        def test_method():
            return True

        def fake_publish(type, method, config):
            return True

        self.m._publish_service = fake_publish
        self.m.config = json.loads('{"imageServices": {"services": [{"input": "\\\\foo\\bar\\baz","connectionFilePath": "my/service/connection"}]}}')
        self.assertTrue(self.m.check_service_type('imageServices', '\\foo\bar\baz', test_method))

    # class TestAnalysis(TestCase):
    #     def test_Analysis_Successful(self):
    #         pass

if __name__ == '__main__':

    unittest.main()<commit_msg>Adds tests for mxd analysis<commit_after>import json
import unittest
from unittest import TestCase
from mock import MagicMock, patch
mock_arcpy = MagicMock()
patch.dict("sys.modules", arcpy=mock_arcpy).start()

from ags_publishing_tools.MapServicePublisher import MapServicePublisher

class TestMapServicePublisher(TestCase):
    m = None

    def setUp(self):
        self.m = MapServicePublisher()
        self.m.config = {
            'connectionFilePath': 'my/connection',
            'mapServices': {
                'services': [
                    {
                        'input': 'foo'
                    }
                ]
            }
        }

    def connection_file_paths_match(self, path, config):
        self.assertEqual(self.m.currentDirectory + path, self.m.get_connection_file_path('mapServices', config))

    def test_get_top_level_connection_file_path(self):
        self.connection_file_paths_match('my/connection', {'input': 'foo'})

    def test_get_type_level_connection_file_path(self):
        self.m.config = {
            'mapServices': {
                'connectionFilePath': 'my/type/connection',
                'services': [
                    {
                        'input': 'foo'
                    }
                ]
            }
        }
        self.connection_file_paths_match('my/type/connection', {'input': 'foo'})

    def test_get_service_level_connection_file_path(self):
        self.m.config = {
            'mapServices': {
                'services': [
                    {
                        'input': 'foo',
                        'connectionFilePath': 'my/service/connection'
                    }
                ]
            }
        }
        self.connection_file_paths_match('my/service/connection', {
            'input': 'foo',
            'connectionFilePath': 'my/service/connection'
        })

    def test_raise_exception_when_input_not_found(self):
        with self.assertRaises(ValueError):
            self.m.publish_input('bar')

    def test_check_service_type_with_backslashes_in_input(self):
        def test_method():
            return True

        def fake_publish(type, method, config):
            return True

        self.m._publish_service = fake_publish
        self.m.config = json.loads('{"imageServices": {"services": [{"input": "\\\\foo\\bar\\baz","connectionFilePath": "my/service/connection"}]}}')
        self.assertTrue(self.m.check_service_type('imageServices', '\\foo\bar\baz', test_method))

    def test_analysis_successful_true(self):
        self.assertTrue(self.m.analysis_successful({}))

    def test_analysis_successful_raises_exception(self):
        with self.assertRaises(RuntimeError):
            self.m.analysis_successful({'foo': 'bar'})

if __name__ == '__main__':

    unittest.main()
{'fraction_non_alphanumeric': 0.1148982957669049, 'fraction_numerical': 0.0, 'mean_word_length': 2.0005497526113247, 'pattern_counts': {'":': 8, '<': 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': '2627627', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1478, 'n_words': 231}