<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import json <EOL> import os <EOL> import string <EOL> from textwrap import dedent <EOL> from pants . build_graph . target import Target <EOL> from pants . util . contextutil import temporary_dir <EOL> from pants_test . tasks . task_test_base import TaskTestBase <EOL> from pants . contrib . node . targets . node_module import NodeModule <EOL> from pants . contrib . node . targets . node_remote_module import NodeRemoteModule <EOL> from pants . contrib . node . targets . node_test import NodeTest <EOL> from pants . contrib . node . tasks . node_task import NodeTask <EOL> class NodeTaskTest ( TaskTestBase ) : <EOL> class TestNodeTask ( NodeTask ) : <EOL> def execute ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return cls . TestNodeTask <EOL> def test_is_node_package ( self ) : <EOL> expected = { <EOL> NodeRemoteModule : True , <EOL> NodeModule : True , <EOL> NodeTest : False , <EOL> Target : False , <EOL> } <EOL> self . assertEqual ( expected , self . _type_check ( expected . keys ( ) , NodeTask . is_node_package ) ) <EOL> def test_is_node_module ( self ) : <EOL> expected = { <EOL> NodeRemoteModule : False , <EOL> NodeModule : True , <EOL> NodeTest : False , <EOL> Target : False , <EOL> } <EOL> self . assertEqual ( expected , self . _type_check ( expected . keys ( ) , NodeTask . is_node_module ) ) <EOL> def test_is_node_remote_module ( self ) : <EOL> expected = { <EOL> NodeRemoteModule : True , <EOL> NodeModule : False , <EOL> NodeTest : False , <EOL> Target : False , <EOL> } <EOL> self . assertEqual ( expected , self . _type_check ( expected . keys ( ) , NodeTask . is_node_remote_module ) ) <EOL> def test_is_node_test ( self ) : <EOL> expected = { <EOL> NodeRemoteModule : False , <EOL> NodeModule : False , <EOL> NodeTest : True , <EOL> Target : False , <EOL> } <EOL> self . assertEqual ( expected , self . _type_check ( expected . keys ( ) , NodeTask . is_node_test ) ) <EOL> def _type_check ( self , types , type_check_function ) : <EOL> self . maxDiff = None <EOL> target_names = [ '<STR_LIT::>' + letter for letter in list ( string . ascii_lowercase ) ] <EOL> types_with_target_names = zip ( types , target_names ) <EOL> type_check_results = [ ( type , type_check_function ( self . make_target ( target_name , type ) ) ) <EOL> for ( type , target_name ) in types_with_target_names ] <EOL> return dict ( type_check_results ) <EOL> def test_execute_node ( self ) : <EOL> task = self . create_task ( self . context ( ) ) <EOL> with temporary_dir ( ) as chroot : <EOL> script = os . path . join ( chroot , '<STR_LIT>' ) <EOL> proof = os . path . join ( chroot , '<STR_LIT:path>' ) <EOL> with open ( script , '<STR_LIT:w>' ) as fp : <EOL> fp . write ( dedent ( """<STR_LIT>""" ) . format ( proof = proof ) ) <EOL> self . assertFalse ( os . path . exists ( proof ) ) <EOL> returncode , command = task . execute_node ( args = [ script ] ) <EOL> self . assertEqual ( <NUM_LIT:0> , returncode ) <EOL> self . assertTrue ( os . path . exists ( proof ) ) <EOL> with open ( proof ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) . strip ( ) ) <EOL> def test_execute_npm ( self ) : <EOL> task = self . create_task ( self . context ( ) ) <EOL> with temporary_dir ( ) as chroot : <EOL> proof = os . path . join ( chroot , '<STR_LIT>' ) <EOL> self . assertFalse ( os . path . exists ( proof ) ) <EOL> package = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( proof ) <EOL> } <EOL> } <EOL> with open ( os . path . join ( chroot , '<STR_LIT>' ) , '<STR_LIT:wb>' ) as fp : <EOL> json . dump ( package , fp ) <EOL> returncode , command = task . execute_npm ( args = [ '<STR_LIT>' , '<STR_LIT>' ] , cwd = chroot ) <EOL> self . assertEqual ( <NUM_LIT:0> , returncode ) <EOL> self . assertTrue ( os . path . exists ( proof ) ) <EOL> with open ( proof ) as fp : <EOL> self . assertEqual ( '<STR_LIT>' , fp . read ( ) . strip ( ) ) </s>
