def test_install_no_init_nodevnoprod(self): # install implies init stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution( dict( script_name='setup.py', script_args=['yarn', '--install'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # The cli will still automatically write to that, as install # implies init. self.assertEqual( result, { 'dependencies': { 'jquery': '~1.11.0' }, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_yarn, 'install'], ))
def test_install_no_init_has_package_json_interactive_default_input(self): stub_stdin(self, u'') stub_mod_call(self, cli) tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({ 'dependencies': {'jquery': '~3.0.0'}, 'devDependencies': {} }, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # Existing package.json will not be overwritten. self.assertEqual(result, { 'dependencies': {'jquery': '~3.0.0'}, 'devDependencies': {}, }) # Ensure that install is NOT called. self.assertIsNone(self.call_args)
def test_init_merge(self): # --merge without --interactive implies overwrite tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': { 'underscore': '~1.8.0', }, 'devDependencies': { 'sinon': '~1.17.0', }}, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--merge'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # gets overwritten as we explicitly asked self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0', 'underscore': '~1.8.0'}, 'devDependencies': {'sinon': '~1.17.0'}, 'name': 'foo', })
def test_init_merge(self): # --merge without --interactive implies overwrite tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': { 'underscore': '~1.8.0', }, 'devDependencies': { 'sinon': '~1.17.0', }}, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--init', '--merge'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # gets overwritten as we explicitly asked self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0', 'underscore': '~1.8.0'}, 'devDependencies': {'sinon': '~1.17.0'}, 'name': 'foo', })
def test_init_overwrite(self): tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': {}, 'devDependencies': {}}, fd) os.chdir(tmpdir) dist = Distribution( dict( script_name='setup.py', script_args=['yarn', '--init', '--overwrite'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # gets overwritten anyway. self.assertEqual( result, { 'dependencies': { 'jquery': '~1.11.0' }, 'devDependencies': {}, 'name': 'foo', }) stdout = sys.stdout.getvalue() self.assertIn("wrote '%s'\n" % join(tmpdir, 'package.json'), stdout)
def test_init_merge_interactive_default(self): tmpdir = mkdtemp(self) stub_stdin(self, u'') with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': { 'underscore': '~1.8.0', }, 'devDependencies': { 'sinon': '~1.17.0', }}, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--merge', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() stdout = sys.stdout.getvalue() self.assertIn('+ "jquery": "~1.11.0",', stdout) with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # Nothing happened. self.assertEqual(result, { 'dependencies': {'underscore': '~1.8.0'}, 'devDependencies': {'sinon': '~1.17.0'}, })
def test_install_view(self): stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution( dict( script_name='setup.py', script_args=['npm', '--install', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual( result, { 'dependencies': { 'jquery': '~1.11.0' }, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_npm, 'install'], ))
def test_install_no_init_nodevnoprod(self): # install implies init stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # The cli will still automatically write to that, as install # implies init. self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
def test_install_no_init_has_package_json_interactive_default_input(self): stub_stdin(self, u'') stub_mod_call(self, cli) tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({ 'dependencies': {'jquery': '~3.0.0'}, 'devDependencies': {} }, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--install', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # Existing package.json will not be overwritten. self.assertEqual(result, { 'dependencies': {'jquery': '~3.0.0'}, 'devDependencies': {}, }) # Ensure that install is NOT called. self.assertIsNone(self.call_args)
def test_init_merge_interactive_default(self): tmpdir = mkdtemp(self) stub_stdin(self, u'') with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': { 'underscore': '~1.8.0', }, 'devDependencies': { 'sinon': '~1.17.0', }}, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--init', '--merge', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() stdout = sys.stdout.getvalue() self.assertIn('+ "jquery": "~1.11.0",', stdout) with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # Nothing happened. self.assertEqual(result, { 'dependencies': {'underscore': '~1.8.0'}, 'devDependencies': {'sinon': '~1.17.0'}, })
def test_init_overwrite(self): tmpdir = mkdtemp(self) with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({'dependencies': {}, 'devDependencies': {}}, fd) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--overwrite'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) # gets overwritten anyway. self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) stdout = sys.stdout.getvalue() self.assertIn("wrote '%s'\n" % join(tmpdir, 'package.json'), stdout)
def test_install_init_install_develop(self): stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution( dict( script_name='setup.py', script_args=['yarn', '--init', '--install', '--development'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual( result, { 'dependencies': { 'jquery': '~1.11.0' }, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ([which_yarn, 'install', '--production=false'], ))
def test_interactive_only(self): tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '-i'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_init_no_overwrite_default_input_interactive(self): tmpdir = mkdtemp(self) stub_stdin(self, u'') # default should be no with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump({ 'dependencies': {}, 'devDependencies': {} }, fd, indent=None) os.chdir(tmpdir) dist = Distribution( dict( script_name='setup.py', script_args=['yarn', '--init', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: # Should not have overwritten result = json.loads(fd.readline()) self.assertEqual(result, { 'dependencies': {}, 'devDependencies': {}, }) stdout = sys.stdout.getvalue() self.assertTrue(stdout.startswith("running yarn\n")) target = join(tmpdir, 'package.json') self.assertIn( "generating a flattened 'package.json' for 'foo'\n" "Generated 'package.json' differs with '%s'" % (target), stdout, ) # That the diff additional block is inside self.assertIn( '+ "dependencies": {\n' '+ "jquery": "~1.11.0"\n' '+ },', stdout, ) self.assertIn( "not overwriting existing '%s'\n" % target, sys.stderr.getvalue(), )
def test_interactive_only(self): tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '-i'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_init_no_overwrite_default_input_interactive(self): tmpdir = mkdtemp(self) stub_stdin(self, u'') # default should be no with open(os.path.join(tmpdir, 'package.json'), 'w') as fd: json.dump( {'dependencies': {}, 'devDependencies': {}}, fd, indent=None) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--init', '--interactive'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: # Should not have overwritten result = json.loads(fd.readline()) self.assertEqual(result, { 'dependencies': {}, 'devDependencies': {}, }) stdout = sys.stdout.getvalue() self.assertTrue(stdout.startswith("running yarn\n")) target = join(tmpdir, 'package.json') self.assertIn( "generating a flattened 'package.json' for 'foo'\n" "Generated 'package.json' differs with '%s'" % (target), stdout, ) # That the diff additional block is inside self.assertIn( '+ "dependencies": {\n' '+ "jquery": "~1.11.0"\n' '+ },', stdout, ) self.assertIn( "not overwriting existing '%s'\n" % target, sys.stderr.getvalue(), )
def test_view(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_view(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_install_dryrun(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--install', '--dry-run'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # Ensure that install is NOT called. self.assertIsNone(self.call_args) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # However, default action is view, the package.json should be # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_install_dryrun(self): stub_mod_call(self, cli) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install', '--dry-run'], name='foo', )) dist.parse_command_line() dist.run_commands() self.assertFalse(exists(join(tmpdir, 'package.json'))) # Ensure that install is NOT called. self.assertIsNone(self.call_args) # also log handlers removed. self.assertEqual(len(getLogger('calmjs.cli').handlers), 0) # However, default action is view, the package.json should be # written to stdout with the correct indentation level. self.assertIn('\n "jquery": "~1.11.0"', sys.stdout.getvalue())
def test_install_view(self): stub_mod_call(self, cli) stub_base_which(self, which_yarn) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['yarn', '--install', '--view'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) self.assertEqual(self.call_args[0], ([which_yarn, 'install'],))
def test_install_init_install_develop(self): stub_mod_call(self, cli) stub_base_which(self, which_npm) tmpdir = mkdtemp(self) os.chdir(tmpdir) dist = Distribution(dict( script_name='setup.py', script_args=['npm', '--init', '--install', '--development'], name='foo', )) dist.parse_command_line() dist.run_commands() with open(os.path.join(tmpdir, 'package.json')) as fd: result = json.load(fd) self.assertEqual(result, { 'dependencies': {'jquery': '~1.11.0'}, 'devDependencies': {}, 'name': 'foo', }) # Should still invoke install self.assertEqual(self.call_args[0], ( [which_npm, 'install', '--production=false'],))