How do I parse and write XML using Python’s ElementTree without moving namespaces around?

As far as I know the solution that better suits your needs is to write a pure Python custom rendering using the features exposed by xml.etree.ElementTree. Here is one possible solution: from xml.etree import ElementTree as ET from re import findall, sub def render(root, buffer=””, namespaces=None, level=0, indent_size=2, encoding=’utf-8′): buffer += f'<?xml version=”1.0″ encoding=”{encoding}” ?>\n’ … Read more

Is it a good way of unit testing to use another, tested function to make preparations for the actual test?

In a perfect world, every unit test can only be broken in single way. Every unit test “lives” in isolation to every other. Your addNewFruit test can be broken by breaking isInFruitsList – but luckily, this isn’t a perfect world either. Since you already tested isInFruitsList method, you shouldn’t worry about that. That’s like using … Read more

CollectionAssert in jUnit?

Using JUnit 4.4 you can use assertThat() together with the Hamcrest code (don’t worry, it’s shipped with JUnit, no need for an extra .jar) to produce complex self-describing asserts including ones that operate on collections: import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.*; import static org.hamcrest.CoreMatchers.*; List<String> l = Arrays.asList(“foo”, “bar”); assertThat(l, hasItems(“foo”, “bar”)); assertThat(l, not(hasItem((String) null))); … Read more

.NET NUnit test – Assembly.GetEntryAssembly() is null

Implement the SetEntryAssembly(Assembly assembly) method given in http://frostwave.googlecode.com/svn-history/r75/trunk/F2DUnitTests/Code/AssemblyUtilities.cs to your unit test project. /// <summary> /// Use as first line in ad hoc tests (needed by XNA specifically) /// </summary> public static void SetEntryAssembly() { SetEntryAssembly(Assembly.GetCallingAssembly()); } /// <summary> /// Allows setting the Entry Assembly when needed. /// Use AssemblyUtilities.SetEntryAssembly() as first line in XNA … Read more