def test_new_symbol_avoids_conflicts(self): namer = naming.Namer({'temp': 1}, True, None, ()) # temp is reserved in the global namespace self.assertEqual('temp_1', namer.new_symbol('temp', set())) # temp_2 is reserved in the local namespace self.assertEqual('temp_3', namer.new_symbol('temp', set(('temp_2',)))) self.assertItemsEqual(('temp_1', 'temp_3'), namer.generated_names)
def test_compiled_function_name_avoids_global_conflicts(self): def foo(): pass namer = naming.Namer({'tf__foo': 1}, True, None, ()) self.assertEqual(('tf__foo_1', True), namer.compiled_function_name('foo', foo))
def test_compiled_function_name_consistent(self): def foo(): pass namer = naming.Namer({}, True, None, ()) self.assertEqual(('tf__foo', True), namer.compiled_function_name( 'foo', foo)) self.assertEqual(('tf__foo', True), namer.compiled_function_name( 'foo', foo))
def test_compiled_function_name_tracks_names(self): def bar(): pass namer = naming.Namer({}, True, None, ()) self.assertEqual(('tf__foo', True), namer.compiled_function_name('foo')) self.assertEqual(('tf__bar', True), namer.compiled_function_name( 'bar', bar)) self.assertEqual({bar: 'tf__bar'}, namer.renamed_calls) self.assertItemsEqual(('tf__bar', 'tf__foo'), namer.generated_names)
def new_namer(self, namespace): return naming.Namer(namespace, self.recursive, self.name_map, self.partial_types)
def test_new_symbol_avoids_duplicates(self): namer = naming.Namer({}, True, None, ()) self.assertEqual('temp', namer.new_symbol('temp', set())) self.assertEqual('temp_1', namer.new_symbol('temp', set())) self.assertItemsEqual(('temp', 'temp_1'), namer.generated_names)
def test_new_symbol_tracks_names(self): namer = naming.Namer({}, True, None, ()) self.assertEqual('temp', namer.new_symbol('temp', set())) self.assertItemsEqual(('temp',), namer.generated_names)