Django test FileField using test fixtures

Django provides a great way to write tests on FileFields without mucking about in the real filesystem – use a SimpleUploadedFile. from django.core.files.uploadedfile import SimpleUploadedFile my_model.file_field = SimpleUploadedFile(‘best_file_eva.txt’, b’these are the contents of the txt file’) It’s one of django’s magical features-that-don’t-show-up-in-the-docs :). However it is referred to here.

How do I unit test a custom ActionFilter in ASP.Net MVC

You just need to test the filter itself. Just create an instance and call the OnActionExecuted() method with test data then check the result. It helps to pull the code apart as much as possible. Most of the heavy lifting is done inside the CsvResult class which can be tested individually. You don’t need to … Read more

Display python unittest results in nice, tabular form [closed]

This is not exactly what you are asking, but there are several options for having a readable test output there: HTMLTestRunner generates easy to use HTML test reports in a tabular form. Here’s a sample report. nose-html-output plugin for nose test runner unittest-xml-reporting – PyUnit-based test runner with JUnit like XML reporting nose with –with-xunit … Read more

Unit Testing – What not to test

I’m not sure I can agree with any of the exceptions that you mention in your answer. Methods not involving logic Even if a method simply just delegates its implementation to an inner dependency, it is very relevant to verify that it happens. I presume that you write code for a reason, so you need … Read more

Run Tensorflow unit tests

The easiest way to run the TensorFlow unit tests is using Bazel, assuming you have downloaded the source from Git: # All tests (for C++ changes). $ bazel test //tensorflow/… # All Python tests (for Python front-end changes). $ bazel test //tensorflow/python/… # All tests (with GPU support). $ bazel test -c opt –config=cuda //tensorflow/… … Read more

python check if a method is called without mocking it away

You can set the Mock.side_effect to be the original method. from unittest.mock import MagicMock class A(): def tmp(self): print(“hi”) def b(a): a.tmp() a = A() a.tmp = MagicMock(side_effect=a.tmp) b(a) a.tmp.assert_called() When side_effect is a function (or a bound method in this case, which is a kind of function), calling the Mock will also call the … Read more

How to test ‘private’ functions in an angular service with Karma and Jasmine

There is no way to test those functions. Their scope is the function that comprises your BracketService factory and they are invisible anyplace else. If you want to test them, then you have to expose them somehow. You can move them into their own service (which seems like overkill) or you can black box test … Read more

bindToController in unit tests

In Angular 1.3 (see below for 1.4+) Digging into the AngularJS source code I found an undocumented third argument to the $controller service called later (see $controller source). If true, $controller() returns a Function with a property instance on which you can set properties. When you’re ready to instantiate the controller, call the function and … Read more