def test_troublesomeHexThird(self): reader = asciimaps.AsciiMapHexThird() lattice = reader.readMap(HEX_THIRD_MAP_2) writer = asciimaps.AsciiMapHexThird(lattice) with io.StringIO() as stream: writer.writeMap(stream) asStr = stream.getvalue() self.assertEqual(asStr, HEX_THIRD_MAP_2)
def _writeAsciiMap(self): """Generate an ASCII map representation.""" lattice = {} for ring, pos in sorted(list(self.assemTypeByIndices)): specifier = self.assemTypeByIndices[(ring, pos)] i, j = grids.getIndicesFromRingAndPos(ring, pos) lattice[i, j] = specifier geomMap = asciimaps.AsciiMapHexThird(lattice) geomMap.writeMap(sys.stdout)
def _read_yaml_lattice(self, system): """Read a ascii map string into this object.""" mapTxt = system[INP_LATTICE] if self.geomType == HEX and THIRD_CORE in self.symmetry: geomMap = asciimaps.AsciiMapHexThird() geomMap.readMap(mapTxt) for (i, j), spec in geomMap.lattice.items(): if spec == "-": # skip whitespace placeholders continue ring, pos = grids.indicesToRingPos(i, j) self.assemTypeByIndices[(ring, pos)] = spec self.maxRings = max(ring, self.maxRings) else: raise ValueError( f"ASCII map reading from geom/symmetry: {self.geomType}/" f"{self.symmetry} not supported.")
def test_hexThird(self): """Check some third-symmetry maps against known answers.""" reader = asciimaps.AsciiMapHexThird() lattice = reader.readMap(HEX_THIRD_MAP) self.assertEqual(lattice[7, 0], "2") self.assertEqual(lattice[8, 0], "3") self.assertEqual(lattice[8, -4], "2") self.assertEqual(lattice[0, 8], "3") self.assertEqual(lattice[0, 0], "1") with self.assertRaises(KeyError): lattice[10, 0] # pylint: disable=pointless-statement with io.StringIO() as stream: reader.writeMap(stream) stream.seek(0) output = stream.read() self.assertEqual(output, HEX_THIRD_MAP)