Skip to content

Commit 0b06fb7

Browse files
committed
fix version, variant and urn
1 parent fedac0f commit 0b06fb7

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/uuid.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,22 @@ impl PyUuid {
4545
}
4646

4747
#[getter]
48-
pub fn urn(&self) -> &str {
49-
let mut buffer = Uuid::encode_buffer();
50-
self.lib_uuid.urn().encode_lower(&mut buffer);
51-
"foo"
48+
pub fn urn(&self) -> String {
49+
format!("{}", self.lib_uuid.urn())
5250
}
5351

5452
#[getter]
55-
pub fn variant(&self) -> &str {
56-
// self.lib_uuid.get_variant().to_string().as_str()
57-
"bar"
53+
pub fn variant(&self) -> String {
54+
format!("{}", self.lib_uuid.get_variant())
5855
}
5956

6057
#[getter]
6158
pub fn version(&self) -> usize {
6259
self.lib_uuid.get_version_num()
6360
}
6461

65-
pub fn __str__(&self) -> &str {
66-
// self.lib_uuid.hyphenated().to_string().as_str()
67-
"baz"
62+
pub fn __str__(&self) -> String {
63+
format!("{}", self.lib_uuid.hyphenated())
6864
}
6965

7066
pub fn __repr__(&self) -> String {

tests/validators/test_uuid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def test_uuid_ok(py_and_json: PyAndJson):
1010
assert isinstance(uuid, Uuid)
1111
assert str(uuid) == '12345678-1234-5678-1234-567812345678'
1212
assert repr(uuid) == "Uuid('12345678-1234-5678-1234-567812345678')"
13-
assert uuid.version == 4
14-
assert uuid.urn == 'foo'
15-
assert uuid.variant == 'bar'
13+
assert uuid.urn == 'urn:uuid:12345678-1234-5678-1234-567812345678'
14+
assert uuid.version == 5
15+
assert uuid.variant == 'NCS'
1616

1717

1818
def test_uuid_from_constructor_ok():
@@ -21,6 +21,6 @@ def test_uuid_from_constructor_ok():
2121
assert isinstance(uuid, Uuid)
2222
assert str(uuid) == '12345678-1234-5678-1234-567812345678'
2323
assert repr(uuid) == "Uuid('12345678-1234-5678-1234-567812345678')"
24-
assert uuid.version == 4
25-
assert uuid.urn == 'foo'
26-
assert uuid.variant == 'bar'
24+
assert uuid.urn == 'urn:uuid:12345678-1234-5678-1234-567812345678'
25+
assert uuid.version == 5
26+
assert uuid.variant == 'NCS'

0 commit comments

Comments
 (0)