Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/test_trace_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import pathlib
import re
import shutil
import tempfile
Expand Down Expand Up @@ -561,6 +562,23 @@ def test_install_id_from_file_replaces_a_file_with_no_valid_line(self):
made = TraceClient.install_id_from_file(path)
self.assertEqual(made, TraceClient.install_id_from_file(path))

def test_install_id_from_file_writes_an_id_into_an_existing_empty_file(self):
path = os.path.join(self._tmpdir(), "install-id")
open(path, "w", encoding="utf-8").close()
made = TraceClient.install_id_from_file(path)
self.assertEqual(str(uuid.UUID(made)), made)
with open(path, encoding="utf-8") as stored:
self.assertEqual(made + "\n", stored.read(), "an empty file holds no ID, so one is written")

def test_install_id_file_accepts_a_path_object(self):
path = pathlib.Path(self._tmpdir()) / "nested" / "install-id"
made = TraceClient.install_id_from_file(path)
self.assertEqual(made + "\n", path.read_text(encoding="utf-8"), "os.PathLike is written like a str")
self.assertEqual(made, TraceClient.install_id_from_file(path), "and read back like one")
client = TraceClient(self.base_url, "MyGame", "1.2.3", key="k", install_id_file=path)
self.assertEqual(made, client.install_id, "the constructor takes the same os.PathLike")
self.assertEqual({"version": "1.2.3", "install": made}, self._sent_tags(client))

def test_unwritable_install_id_file_yields_an_in_memory_id_and_never_raises(self):
# A path under a regular file cannot be created, even as root.
blocker = os.path.join(self._tmpdir(), "a-file")
Expand Down
Loading