def test_copy_binary(self): with tempfile.TemporaryDirectory() as directory: source = ResourcePath("Packages/test_package/UTF-8-test.txt") destination = Path(directory) / 'UTF-8-test.txt' source.copy(destination) self.assertTrue(destination.is_file()) with open(str(destination), 'rb') as file: data = file.read() self.assertEqual(data, source.read_bytes())
def needs_installation(self) -> bool: installed = False if self._skip_npm_install or path.isdir(path.join(self._server_dest, 'node_modules')): # Server already installed. Check if version has changed or last installation did not complete. src_package_json = ResourcePath(self._server_src, 'package.json') if not src_package_json.exists(): raise Exception('Missing required "package.json" in {}'.format(self._server_src)) src_hash = md5(src_package_json.read_bytes()).hexdigest() try: with open(path.join(self._server_dest, 'package.json'), 'rb') as file: dst_hash = md5(file.read()).hexdigest() if src_hash == dst_hash and not path.isfile(self._installation_marker_file): installed = True except FileNotFoundError: # Needs to be re-installed. pass if installed: self._status = ServerStatus.READY return False return True