Skip to main content

Posts

unable to mock patch in python unittest

I have developed the logic where I am initializing a few variables but with two versions. Initially, my code looked something like this: session = boto3.session.Session() client = session.client( service_name='secretsmanager', region_name="eu-west-1" ) class MyRepo(object): So here, I was able to mock the client directly using a patch because it wasn't an instance variable. After I implemented dependency injection : class MyRepo(object): def __init__(self, region): session = boto3.session.Session() self.client = session.client( service_name='secretsmanager', region_name=region ) Now, I am trying to mock the instance variable which is accessed using the self keyword i.e client . @patch('credentials_repo.my_repo.client') class TestSecretManagerMethod(TestCase): However, when I run the test case it throws an error attached below: raise AttributeError( AttributeError: <module ...

How to convert textarea value to a string in JavaScript

I want to convert the textarea input value to a string, but does not work and output is: [Object HTMLInputElement], I've used regex, it works properly when I hard code a string let input = document.getElementById("input").toString(); let result = input.replace(/(?<=(?:^|[.?!])\W*)[a-z]/g, i => i.toUpperCase()); console.log(result); Via Active questions tagged javascript - Stack Overflow https://ift.tt/YcnQmzt

Can anyone please show me how to use the .push() method for an array?

Ask the user to input names of people they would like to invite to a dinner party. Each name should be added to an array. The user can only invite a maximum of ten people. If they try to add more than 10 names, the program should state, “You have already added 10 people to your guest list.” The program should then output the list. I am trying to solve this task, I am not sure if I am doing it properly. I am a beginner so I will appreciate any help or hints. { let list = []; list.length = 10 while(true){ let input = prompt("Add a guest"); if(input <= 10 || input == null){ break; //arr.slice(0,10) } list.push(String(input)); console.log(list); } } Via Active questions tagged javascript - Stack Overflow https://ift.tt/9yCVw1N

Modify script to get sheet folder ID

I would like some help to modify this script here: Upload multiple large files to Google Drive using Google Apps Script The question is the following: this script uploads to a folder within the folder defined in const uploadParentFolderId = "1cOe4ZXjBUZHgPwADg1QRpUzcQqGxON_4"; which is in the forms.html file, the problem is that I intend to call this script within a spreadsheet through an html alert and I would like that the file was uploaded inside a folder of the spreadsheet folder, that is, the script would need to get the ID of the spreadsheet folder. Javascript is a language that is a little out of my daily life, but I'm trying to learn it on my own... If anyone can give me a light on this, it will be of great help! EDIT: I tried this: var ssid = SpreadsheetApp.getActiveSpreadsheet().getId(); var AllFolders = DriveApp.getFileById(ssid).getParents(); var ChildFolderTest; if (AllFolders.hasNext()) { ChildFolderTest = AllFolders.next(); var FinalFolderID = Chi...

Hugging Face distilbert-base-uncased not predicting well

I have the following script where I'm trying to fine tune distilbert. It seems to train decently fast, but when I run predictions on the model, then they're all over the place. I'm pretty new to python and ML, so it's been hard debugging to figure out what's happening. import tensorflow as tf from datasets import load_dataset import numpy as np from transformers import DistilBertTokenizer, TFAutoModelForSequenceClassification, pipeline, create_optimizer, DataCollatorWithPadding tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased") def train(): def preprocess_function(examples): return tokenizer(examples["text"], truncation=True) dataset = load_dataset('json', data_files='full-items.json') tokenized = dataset.map(preprocess_function, batched=True) data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors="tf") batch_size = 16 num_epochs = 5 ...

this.watch vs. on Mutate for handling changes in a backdraft watchable

In a backdraftjs component with watchable 'titleString', is there any difference/preference between this.watch('titleString', this.handleTitleStringChange); and onMutateTitleString(newTitle, oldTitle) { ... } The onMutate has the benefit that it remembers the old value ( oldTitle ) but this.watch() is maybe a little easier to find in code since it contains the word titleString -- where for onMutate you have to know to search for the camelcased-and-concatenated version. Are there any other reasons to use one or the other? Via Active questions tagged javascript - Stack Overflow https://ift.tt/9yCVw1N

error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native

I am trying to run react native app on Andriod but I am getting this error presets: ['module:metro-react-native-babel-preset'], , Could someone please help me to how to resolve this issue. const {getDefaultConfig} = require('metro-config'); module.exports = { transformer: { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, inlineRequires: true, }, }), }, }; module.exports = (async () => { const { resolver: {sourceExts, assetExts}, } = await getDefaultConfig(); return { transformer: { babelTransformerPath: require.resolve('react-native-svg-transformer'), }, resolver: { assetExts: assetExts.filter(ext => ext !== 'svg'), sourceExts: [...sourceExts, 'svg'], }, }; })(); Via Active questions tagged javascript - Stack Overflow https://ift.tt/9yCVw1N