<s> import os <EOL> import sys <EOL> from test import CollectorTestCase <EOL> from test import get_collector_config <EOL> from test import unittest <EOL> from test import run_only <EOL> from mock import patch <EOL> from diamond . collector import Collector <EOL> from userscripts import UserScriptsCollector <EOL> def run_only_if_kitchen_is_available ( func ) : <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> try : <EOL> from kitchen . pycompat27 import subprocess <EOL> except ImportError : <EOL> subprocess = None <EOL> else : <EOL> import subprocess <EOL> pred = lambda : subprocess is not None <EOL> return run_only ( func , pred ) <EOL> class TestUserScriptsCollector ( CollectorTestCase ) : <EOL> def setUp ( self ) : <EOL> config = get_collector_config ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : os . path . dirname ( __file__ ) + '<STR_LIT>' , <EOL> } ) <EOL> self . collector = UserScriptsCollector ( config , None ) <EOL> def test_import ( self ) : <EOL> self . assertTrue ( UserScriptsCollector ) <EOL> @ run_only_if_kitchen_is_available <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_work_with_example ( self , publish_mock ) : <EOL> self . collector . collect ( ) <EOL> metrics = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> self . setDocExample ( collector = self . collector . __class__ . __name__ , <EOL> metrics = metrics ) <EOL> self . assertPublishedMany ( publish_mock , metrics ) <EOL> @ run_only_if_kitchen_is_available <EOL> @ patch . object ( Collector , '<STR_LIT>' ) <EOL> def test_should_skip_over_unrunnable_files ( self , publish_mock ) : <EOL> self . collector . collect ( ) <EOL> assert publish_mock . call_args_list <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
