I have a flutter app which contains a large list of quotes, each with an associated audio file.
I've written a simple test that verifies all the specified audio files are where they're supposed to be, in case of typos etc:
test('specified audio file should exist for all quotes', () {
ALL_QUOTES.forEach((quote) {
final expectedPath = 'assets/${quote.filename}.wav';
final exists = new File(expectedPath).existsSync();
expect(exists, isTrue, reason: '$expectedPath does not exist');
});
});
This passes fine in IntelliJ, however running from the command line using flutter test it fails on the first thing it looks for.
Is there a way of doing this which will work regardless of how it's run? Why does it pass one way but not the other?
Ok so I got to the bottom of this, and it is something you can do in a unit test.
To diagnose, I added the line print(Directory.current); to the test. Running in IntelliJ, I get /home/project_name. From the command line, it's /home/project_name/test. So just a simple file path thing to resolve.
Edited to include Ovidiu's simpler logic for getting the right asset path
void main() {
test('specified audio file should exist for all quotes', () {
ALL_QUOTES.forEach((quote) {
final expectedPath = 'assets/${quote.filename}.wav';
final exists = _getProjectFile(expectedPath).existsSync();
expect(exists, isTrue, reason: '$expectedPath does not exist');
});
});
}
File _getProjectFile(String path) {
final String assetFolderPath = Platform.environment['UNIT_TEST_ASSETS'];
return File('$assetFolderPath/$path');
}
Related
I'm a beginner developer just starting with HMS. I'm trying to write a code that finds the "profile.json" file, which was previously uploaded to the cloud into the folder "DebtSorter". My code (Kotlin) for it currently looks like:
var fileList: MutableList<File?> = mutableListOf()
thread {
try {
val drive = buildDrive()
val request = drive.files().list()
var cursor: String?
fileList = ArrayList()
do {
var result = request.setQueryParam("fileName contains 'profile'")
.setOrderBy("fileName")
.setPageSize(10)
.setFields("*")
.execute()
for (file in result.files) {
fileList.add(file)
}
cursor = result.nextCursor
request.cursor = cursor
} while (!StringUtils.isNullOrEmpty(cursor))
} catch (e: java.lang.Exception) {
Toast.makeText(applicationContext, "executeFilesList exception: $e", Toast.LENGTH_LONG)
.show()
}
}
return fileList
However, the returned fileList is always empty, even when I upload the file to the root of the cloud. I think I'm messing something up with the query string, because I can upload files just fine. Can someone tell me the syntax and keywords used in the query string, and possibly help me with the code and how to search in a given folder in HMS Drive kit?
Update:
You can also refer to the demo: https://github.com/HMS-Core/hms-drive-serverdemo In the demo, the thread executes the method of obtaining the file list directly.
Your query parameters is incorrect. You can't define the format of your query string. Please refer to this sample query statement.
(assuming that the ID of folder A is f192358798744098816):
To query all files in folder A, run the following statement: 'f192358798744098816' in parentFolder and mimeType != 'application/vnd.huawei-apps.folder'
To query all folders in the recycle bin, run the following statement: mimeType='application/vnd.huawei-apps.folder' and recycled=true
The query criteria 'fileId' in parentFolder and recycled=true cannot be used together, that is, a user cannot query files or folders in a specified parent folder in the recycle bin.
For more details, see the official guide.
In the end, the problem was with creating the thread. Since the thread is asynchronous and I created the fileList variable before the thread, modified it in the thread and returned it after the thread, the actual modification happened after the method already returned with the empty fileList. I took out the lines with thread and put the method call into a thread. This solved it.
When trying to publish projects from a solution using the below gulp task it working fine.
var publish = function (projectPath) {
return gulp.src([projectPath + "/**/*.csproj"])
.pipe(foreach(function (stream, file) {
return publishStream(stream, file);
}));
But when I pass an array with my project name in to gulp.src like below, publishing only one project and the task is exited. (here 'projects' is my array of projects)
return gulp.src(projects)
.pipe(foreach(function (stream, file) {
return publishStream(stream, file);
}));
What may be the reason
You have to provide the root folder as second parameter as shown below.
gulp.src(['bower_components/jquery/jquery.js',
'bower_components/superscrollorama/js/greensock/TweenMax.min.js',
'bower_components/superscrollorama/jquery.superscrollorama.js' ],
{base: 'bower_components/'})
.pipe(...);
Please have a look at Why does gulp.src not like being passed an array of complete paths to files?.
public function actionCreate()
{
$model=new Patient('patientScenario');
if(isset($_POST['Patient']))
{
$model->attributes=$_POST['Patient'];
$model->image= CUploadedFile::getInstance($model,'image');
if($model->save())
{
$imagePath = Yii::app()->params['DataFolder'];
if($model->image!="")
{
if(!(file_exists($imagePath)))
{
mkdir($imagePath,'0777',true);
}
}
$model->image->saveAs($imagePath.$model->id.'_'.$model->image->name);
$ns=new newserver(); $ns->uploadFile($filepath,$imagePath.$model->id.'_'.$model->image->name, $model->id.'_'.$model->image->name);
}
}}
It is a action with lot of codes I have simplified it to focus on the issue here.
The issue is while creating a patient, If I upload a image its working fine, But even though I don't upload an image the condition $model->image!="" became true and obviously there will be no file name and while trying to upload on the new server class I get
fopen(22522_): failed to open stream: No such file or directory
I tried ($model->image!==NULL) as well. still getting the same error.
But it works fine in my localhost, But not in the server.
Your problem is on newserver() class
On that class you are tried to open a file .
Check condition before the file open on newserver() class
or give a code on newserver Class
I have a play application running on a linux server. The play application handles an ajax request, the controller code that handles the request :
public static Result getStorageId() {
final String host = request().username();
logger.debug("get storage id from origin:" + host);
Promise<Product> promiseProduct = Akka.future(new Callable<Product>() {
#Override
public Product call() throws Exception {
Partner partner = PartnerModel.getPartner(host);
logger.debug("Partner origin:" + partner.getHost());
** Product productCase = ProductsModel.createProduct();
logger.debug("product created. id:" + productCase.getId());
return productCase;
}
});
return async(promiseProduct
.map(new Function<Product, Result>() {
#Override
public Result apply(Product product) {
return ok();
}
}));
}
The ProductsModel.createProduct() code is
public static Product createProduct(){
logger.debug("creating new product");
Product product = new ProductImpl();
saveProduct(product);
return product;
}
The issue is when an ajax request made the app reaches line ** and stops but there's no error indicated in the application.log file nor in the play console. The debug statement in the first line of createProduct() method is not executed. The app is still running as I can make another ajax request and see the log statement before line **.
I did try "play run" hoping that it might give more info since it runs in debug mode but no luck.
My local development copy works fine. Another thing, I had this issue before and as a desperate attempt I just create a new class "ProductTestModel" with the same functionality as ProductsModel and used it instead of ProductsModel (ie on line ** it goes Product productCase = ProductTestModel.createProduct() ) deployed it and everything worked. Now after several releases I get this problem again.
I'm using GIT to distribute the code to the server and have play compile the app there. Running play clean compile shows no errors.
So what could be the problem?
I found out the root cause of my problem. It's actually a stupid thing, I forgot to include a conf file. Where the code was failing that object was using that conf file.
Talk about hours being wasted!!
I'm trying to write an image file to the localFolder storage. I want to write it specifically to the images/heroes/ folder inside the localFolder. Is there some way to do this with my existing code?
return WinJS.xhr({ url: fileToDownloadURL, responseType: 'blob' }).then(
function (response) {
var input = response.response.msDetachStream();
var filename = 'ms-appx:///local/images/heroes/image_name.png';
Windows.Storage.ApplicationData.current.localFolder.createFileAsync(filename,
Windows.Storage.CreationCollisionOption.replaceExisting).then(
function (file) {
return file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
function (output) {
return Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output).then(
function () {
output.flushAsync().then(function () {
input.close();
output.close();
});
});
});
}
}
)};
I get this error message:
0x8007007b - JavaScript runtime error: The filename, directory name, or volume label syntax is incorrect.
WinRT information: The specified name (ms-appx:///local/images/heroes/image_name.png) contains one or more invalid characters.
I figured it out. For anyone wondering, you can call
getFolderAsync('SomeFolderName')
from the
Windows.Storage.ApplicationData.current.localFolder
instance. getFolderAsync() is like any promise function and will return with an error if the folder does not exist. From there you can run
createFolderAsync('SomeFolderName')
to create the folder, and then continue what you were doing. In my case it was better to create a function like writeFileAsync() and then call it depending on whether or not the folder exists first.
Keep in mind getFolderAsync() can only get one folder at a time, so something like
getFolderAsync('along/list/of/folders')
won't work. You'll have to chain together the getFolderAsync() calls together, I believe (correct me if I'm wrong!).