trouble with coercision in test
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với việc tái hiện TestJinjava.testCoerc và entry point Jinjava.render được nêu trong stack trace. Chạy test với các đối số macro dạng số và dạng chuỗi, sau đó theo dõi hành vi của phép so sánh điều kiện và việc ép kiểu. Hoàn tất khi trường hợp được tái hiện render cả hai mục Fedora với đầu ra mong đợi mà không xảy ra ngoại lệ ép kiểu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi,
Here is a unit test class that reflect my problem:
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import org.junit.Test;
import com.hubspot.jinjava.Jinjava;
public class TestJinjava {
@Test
public void testCoerc() {
String output = new Jinjava().render("{% macro bug(version) %}"
+ "{% set fversion = 'rawhide' if version == 'rawhide' else 'f' + version|string %}"
+ "- name: fedora_{{version}}\n"
+ " url: 'https://src.fedoraproject.org/rpms/{srcname}/tree/{{fversion}}'\n"
+ "{% endmacro %}{{ bug('39') }}{{ bug('rawhide') }}", Collections.emptyMap());
assertEquals("- name: fedora_39\n url: 'https://src.fedoraproject.org/rpms/{srcname}/tree/f39'\n"
+ "- name: fedora_rawhide\n url: 'https://src.fedoraproject.org/rpms/{srcname}/tree/rawhide'\n",
output);
}
}
If bug('19') is replaced by bug(19), test is broken:
com.hubspot.jinjava.interpret.FatalTemplateErrorsException: Cannot coerce 'rawhide' of class java.lang.String to class java.lang.Long (incompatible value)
at com.hubspot.jinjava.Jinjava.render(Jinjava.java:193)
at repology.TestJinjava.testCoerc(TestJinjava.java:15)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
To me this is strange and it is also not possible to replace the condition by something like:
{% set fversion = 'rawhide' if version|string == 'rawhide' else 'f' + version|string %}
isn't it?
This test case was extracted from:
https://github.com/repology/repology-updater/blob/master/repos.d/rpm/fedora.yaml
that use Python Jinja2.
Regards,
Patrice
- Ngôn ngữ chính
- Java
- Star
- 785
- Fork
- 184
- Merge trung bình
- 6 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của HubSpot/jinjava
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
Jinjava 3.0Có thể làm lại được @jasmith-hs đã nhận 207 ngày trước và không có pull request nào đang mở. Đang mở
-
Upgrade to Jackson 3.0.0Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của HubSpot/jinjava
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openhab/openhab-core#5847 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
apache/parquet-java#3820 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
beehive-lab/jllm#187 ·