I think you are aware, that you can create hooks on install process.
Here is my approach, where I after install publish plugin as an example
You can use postflight hook in your demo data extension to uninstall itself programmatically.
I did such a thing in the past but I don't have an example.
Or you can, if you have a plugin you develop which assumed to be installed before the demo data extension install, in that plugin check what is installed and the uninstall that extension. There is a bunch of hooks for it.
And, as an option, you can add an upload button to your component to upload test data and handle it in your component - get uploaded file, extract if needed, run queries from the file. Then no need with install-uninstall programmatically. I'd use such an apporach.
But self-uninstall seems interesting to be implemented just for fun :-)
A point to start looking how to self-uninstall.
Or, dirty way, run query to remove corresponding record from #__extensions and unlink files. But I'd rather examine Joomla API and find a legal way to programmatically uninstall an extension.
The preflight hook
At this point you could conceivably prevent the installation by calling the abort mechanism from the parent or prepare anything ahead of the file copy and database changes occurring.
As an option In preflight hook execute you demo data install code but return false to pervent your extension instllation. Add a message for a user "Demo data installed, ignore joomla error message on
failed installation". :-)